import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};//平年每个月的天数表
while(scan.hasNextInt()) {
int year = scan.nextInt();
int month = scan.nextInt();
int day = days[month - 1];
if(((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) && month == 2) {//对于闰年的二月,需要加1
day += 1;
}
System.out.println(day);
}
}
}