#include <stdio.h>

int main() 
{
    int X = 0, N = 0;
    scanf("%d%d", &X, &N);
    if(X >= 1 && X <= 7 && N >= 1 && N <= 1000)
    {
       X = (X + N) % 7;  //如果是星天的话是0
       if(X == 0)
       {
        X = 7;
       }
        printf("%d", X);
    } 
    return 0;
}