#include <stdio.h>

int main() {

    int year = 0;//初始化
    int month = 0;
    while (scanf("%d %d", &year, &month) != EOF) { //多组输入
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { //判断闰年
            if (month == 2) {
                printf("29\n");
            } else if (month == 4 || month == 6 || month == 9 || month == 11) {
                printf("30\n");
            } else {
                printf("31\n");
            }
        } else {//其他年份
            if (month == 2) {
                printf("28\n");
            } else if (month == 4 || month == 6 || month == 9 || month == 11) {
                printf("30\n");
            } else {
                printf("31\n");
            }
        }
    }
    return 0;
}