#include<bits/stdc++.h>usingnamespace std;boolyJudge(int y){if(y %4==0&& y %100!=0|| y %400==0){returntrue;}returnfalse;}int m1[12]={31,29,31,30,31,30,31,31,30,31,30,31};//闰年int m2[12]={31,28,31,30,31,30,31,31,30,31,30,31};intmain(){int y, d;scanf("%d%d",&y,&d);int flag =0;int t = d;int mongth, date;if(yJudge(y)){for(int i =0; i <12&&t>0; i++){
t = t - m1[i];
mongth = i +1;
date = t + m1[i];}}else{for(int i =0; i <12&&t>0; i++){
t = t - m2[i];
mongth = i +1;
date = t + m2[i];}}printf("%d\n%d",mongth,date);return0;}