import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; while(sc.hasNextInt()) { int year = sc.nextInt(); int month = sc.nextInt(); int day = days[month - 1]; if(((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) && month == 2) { day += 1; } System.out.println(day); } } }