#include <iostream>
#include <cstdio>
using namespace std;
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main(){
int y, d; scanf("%d%d", &y, &d);
if(y % 4 == 0 && y % 100 != 0 || y % 400 == 0) month[2] = 29;
for(int i = 1; i <= 12; i ++ ){
if(d <= month[i]){
cout << i << endl << d << endl;
break;
}
else d -= month[i];
}
return 0;
}