public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        // 1<= x <= 7
        int x = scanner.nextInt();
        
        // 1<= n <= 1000
        int n = scanner.nextInt();
        
        if((x >= 1 && x <= 7) && (n >= 1 && n <= 1000)) {
            
            if(x + n <= 7 ) {
                System.out.println(x + n);
            } else {
                if((x + n) % 7 == 0) {
                    System.out.println(7);
                } else {
                    System.out.println((x + n) % 7);
                }      
            }
            
        } else {
            System.out.println("Input error");
        }
    }
}