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