import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int year  = in.nextInt();
            int month = in.nextInt();
            int[] arr = {1, 3, 5, 7, 8, 10, 12};
            if ( month == 2) {
                if ((year % 4 == 0 && year % 100 != 0 || (year % 400 == 0)) ) {
                    System.out.println(29);
                } else {
                    System.out.println(28);
                }
            } else {
                boolean b = false;
                for ( int i = 0; i < arr.length;i++) {
                    if ( arr[i] == month) {
                        b = true;
                    }
                }
                if (b == true) {
                    System.out.println("31");
                } else {
                    System.out.println(30);
                }

            }

        }
    }
}