import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
//TODO
int n,m;
int run[]={0,31,29,31,30,31,30,31,31,30,31,30};//闰年每个月的天数,由于数组0开始计数所以前面得存一个0让一月份份天数存在run[1]里;
int f[]={0,31,28,31,30,31,30,31,31,30,31,30};//同上非闰年存在这儿。
n = in.nextInt();
m = in.nextInt();
if((m%4==0&&m%100!=0)||m%400==0)System.out.println(run[n]);//是闰年直接输出run[n];
else System.out.println(f[n]);
}
}