import java.time.LocalDate;
import java.time.Month;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int y=sc.nextInt();
int d=sc.nextInt();
LocalDate localDate=LocalDate.of(y,1,1);
localDate=localDate.plusDays(d-1);
System.out.println(localDate.getMonthValue());
System.out.println(localDate.getDayOfMonth());
}
}