#include <stdio.h>

int main() {
    int a, b;
    while (scanf("%d %d",&a,&b)!=EOF){
    if(a%400==0||(a%4==0&&a%100!=0)){
         int arr[12]={31,29,31,30,31,30,31,31,30,31,30,31};
         printf("%d\n",arr[b-1]);
        }
        else {
            int arr2[12]={31,28,31,30,31,30,31,31,30,31,30,31};
            printf("%d\n",arr2[b-1]);
        }
    }
    return 0;
}