public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(bf.readLine(), " "); int E = Integer.parseInt(st.nextToken()); int S = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); int e=1,s=1,m=1; // 1 1 1은 1년을 의미 for(int i=1; ; i++) { // 무한 loop if(e == E && s == S && m == M) { System.out.println(i); break; } e++; s++; m++; if(e == 16) e=1; if(s == 29) s=1; if(m == 20) m=1; } }