import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ECR13B {

	public static void main(String[] args) {
		FastScanner in=new FastScanner();
		int n=in.nextInt();

		int week=1;
		for(int i=1900;i<n;i++){
			if(i%400==0||i%4==0&&i%100!=0){
				week+=366;
			}else{
				week+=365;
			}
			week%=7;
		}

		boolean leap=false;
		if(n%400==0||n%4==0&&n%100!=0) leap=true;

		int week2=week;
		boolean leap2=false;
		for(;;){
			n++;
			if(n%400==0||n%4==0&&n%100!=0){
				leap2=true;
				week2+=366;
			}else{
				leap2=false;
				week2+=365;
			}
			week2%=7;
			if(week==week2&&leap==leap2)
				break;
		}

		System.out.println(n);
	}
	static class FastScanner{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(){br=new BufferedReader(new InputStreamReader(System.in));}
		String nextToken(){
			while(st==null||!st.hasMoreElements())
				try{st=new StringTokenizer(br.readLine());}catch(Exception e){}
			return st.nextToken();
		}
		int nextInt(){return Integer.parseInt(nextToken());}
		long nextLong(){return Long.parseLong(nextToken());}
		double nextDouble(){return Double.parseDouble(nextToken());}
	}
}

//package proje;
import java.util.*;

public class m
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int year = s.nextInt();

		int sum=0;

		if((year%4==0 && year%100!=0)||year%400==0)
		{
			while(!((year%4==0 && year%100!=0)||year%400==0) || sum%7!=0 || sum==0)
			{

				if((year%4==0 && year%100!=0)||year%400==0 )
					sum+=366;
				else
					sum+=365;
				year++;
			}

			System.out.println(year);
		}
		else
		{
			while(true)
			{
				if((year%4==0 && year%100!=0)||year%400==0 )
					sum+=366;
				else
					sum+=365;
				++year;
				if(sum%7==0 && !((year%4==0 && year%100!=0)||year%400==0))
				{
				System.out.println(	year);
				break;
				}

			}
		}
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.time.Year;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author programajor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long y = in.nextLong();
            double count = 0;
            boolean isYearLeap = Year.isLeap(y);
            long next = y + 1;
            while (true) {
                boolean isCurrLeap = Year.isLeap(next);
                if (isCurrLeap) {
                    count += 2;
                } else {
                    count += 1;
                }
                next++;
                if (count % 7 == 0 && isCurrLeap == isYearLeap) {
                    break;
                }
            }
            out.print(next - 1);
        }

    }
}

import java.util.*;

public class CF678B {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int year = in.nextInt();

		int startDay = isLeapYear(year) ? 2 : 1;
		int currYear = year+1;
		while(startDay != 0 || isLeapYear(year) != isLeapYear(currYear)) {
			startDay += isLeapYear(currYear) ? 2 : 1;
			startDay %= 7;
			++currYear;
		}
		System.out.println(currYear - startDay);

	}

	public static boolean isLeapYear(int year) {
		if(year % 400 == 0) return true;
		if(year % 100 == 0) return false;
		if(year % 4 == 0) return true;
		return false;
	}
}

import java.util.Scanner;

public class TheSameCalender {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		boolean isLeap = n%400 == 0 || (n % 4 == 0 && n % 100 != 0);
		boolean isLeap2 = isLeap;
		int first = 0;
		while(true)
		{
			n++;
			first += 365;
			if(isLeap2)
				first++;
			first = first % 7;

			isLeap2 = n%400 == 0 || (n % 4 == 0 && n % 100 != 0);
			if(first == 0 && isLeap2 == isLeap)
			{
				System.out.println(n);
				break;
			}

		}

	}
}

import java.io.*;
public class JavaApplication4{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        int y = x;
        int day = 1;
        int d = 1;
        boolean leap;

        if(y%400 == 0) {leap = true; day = 2; d = 9;}
        else if(y%100 == 0) {leap = false; day = 1; d = 8;}
        else if(y% 4 == 0) {leap = true; day = 2; d = 9;}
        else {leap = false; day = 1; d = 8;}

        boolean year;
        while(true)
        {
            y++;

            if(y % 400 == 0) {year = true; day = day + 2;}
            else if(y % 100 == 0) {year = false; day++;}
            else if(y % 4 == 0) {year = true; day = day + 2;}
            else {year = false; day++;}

            if(day == d && leap == year)
            {
                System.out.print(y);
                break;
            }

            if(day == 8) day = 1;
            if(day == 9) day = 2;
        }
    }
}

					import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
									public class Solution1 implements Runnable
									{
										static final long MAX = 1000000007L;
										static class InputReader
										{
											private InputStream stream;
											private byte[] buf = new byte[1024];
											private int curChar;
											private int numChars;
											private SpaceCharFilter filter;
											private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

											public InputReader(InputStream stream)
											{
												this.stream = stream;
											}

											public int read()
											{
												if (numChars==-1)
													throw new InputMismatchException();

												if (curChar >= numChars)
												{
													curChar = 0;
													try
													{
														numChars = stream.read(buf);
													}
													catch (IOException e)
													{
														throw new InputMismatchException();
													}

													if(numChars <= 0)
														return -1;
												}
												return buf[curChar++];
											}

											public String nextLine()
											{
												String str = "";
									            try
									            {
									                str = br.readLine();
									            }
									            catch (IOException e)
									            {
									                e.printStackTrace();
									            }
									            return str;
											}
											public int nextInt()
											{
												int c = read();

												while(isSpaceChar(c))
													c = read();

												int sgn = 1;

												if (c == '-')
												{
													sgn = -1;
													c = read();
												}

												int res = 0;
												do
												{
													if(c<'0'||c>'9')
														throw new InputMismatchException();
													res *= 10;
													res += c - '0';
													c = read();
												}
												while (!isSpaceChar(c));

												return res * sgn;
											}

											public long nextLong()
											{
												int c = read();
												while (isSpaceChar(c))
													c = read();
												int sgn = 1;
												if (c == '-')
												{
													sgn = -1;
													c = read();
												}
												long res = 0;

												do
												{
													if (c < '0' || c > '9')
														throw new InputMismatchException();
													res *= 10;
													res += c - '0';
													c = read();
												}
												while (!isSpaceChar(c));
													return res * sgn;
											}

											public double nextDouble()
											{
												int c = read();
												while (isSpaceChar(c))
													c = read();
												int sgn = 1;
												if (c == '-')
												{
													sgn = -1;
													c = read();
												}
												double res = 0;
												while (!isSpaceChar(c) && c != '.')
												{
													if (c == 'e' || c == 'E')
														return res * Math.pow(10, nextInt());
													if (c < '0' || c > '9')
														throw new InputMismatchException();
													res *= 10;
													res += c - '0';
													c = read();
												}
												if (c == '.')
												{
													c = read();
													double m = 1;
													while (!isSpaceChar(c))
													{
														if (c == 'e' || c == 'E')
															return res * Math.pow(10, nextInt());
														if (c < '0' || c > '9')
															throw new InputMismatchException();
														m /= 10;
														res += (c - '0') * m;
														c = read();
													}
												}
												return res * sgn;
											}

											public String readString()
											{
												int c = read();
												while (isSpaceChar(c))
													c = read();
												StringBuilder res = new StringBuilder();
												do
												{
													res.appendCodePoint(c);
													c = read();
												}
												while (!isSpaceChar(c));

												return res.toString();
											}

											public boolean isSpaceChar(int c)
											{
												if (filter != null)
													return filter.isSpaceChar(c);
												return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
											}

											public String next()
											{
												return readString();
											}

											public interface SpaceCharFilter
											{
												public boolean isSpaceChar(int ch);
											}
										}

										public static void main(String args[]) throws Exception
										{
											new Thread(null, new Solution1(),"Solution1",1<<26).start();
										}
										long gcd(long a, long b)
									    {
									        if (a == 0)
									            return b;

									        return gcd(b%a, a);
									    }
									    // method to return LCM of two numbers
										 long lcm(long a, long b)
										    {
										        return (a*b)/gcd(a, b);
										    }
										final long bit = 60;
										public void run()
										{
											InputReader sc= new InputReader(System.in);
											PrintWriter w= new PrintWriter(System.out);
											int n = sc.nextInt();
											int q = 365;
											if(n%4==0 && n%100!=0 || n%400==0)
												q++;
											int k = n+1;
											int d = q%7;
											do {
												int nod = 365;
												if(k%4==0 && k%100!=0 || k%400==0)
													nod++;
												if(d==0 && nod==q) {
													w.println(k);
													break;
												}
												d=(d+nod)%7;
												k++;
											}while(true);
											w.close();
										}
										long binaryExponentiationIterative(long x,long n){
											long result = 1;
											while(n > 0){
												if(n % 2 != 0)
													result = (result*x)%MAX;
												x = (x * x)%MAX;
												n = n/2;
											}
											return result;
										}
										static class Pair implements Comparable<Pair>{
											int a;
											long b;

											Pair(){}
											Pair(int a,long b){
												this.a = a;
												this.b = b;

											}
											public int compareTo(Pair p){
												return Integer.compare(this.a,p.a);
											}
										}
						}

import java.util.*;
public class johny {
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		int y=s.nextInt();
		int flag =0;int cnt=0;
		if(IsLeapYear(y))flag=1;
		for(int i =y+1; ; i++){
			cnt++;
			if(IsLeapYear(i))
				cnt++;
			if(cnt%7==0){
				if(flag==1 && IsLeapYear(i)){
					System.out.println(i);
					break;
				}
				else if(flag==0 && !(IsLeapYear(i))){
						System.out.println(i);
						break;
				}
			}

		}

	}
	public static boolean IsLeapYear(int a){
		if(a%400==0 || (a%4==0 && a%100!=0)){
				return true;
		}
		return false;
	}
}

import java.util.*;
import java.io.*;
public class Tester {
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int i,j,k,l=1,r,m=1,n,o,p,t,size,half,count=0,flag=1,size1,y;
		y=sc.nextInt();
		int d=0;
		boolean given=leap(y);
		while(true)
		{
			d++;
			y++;
			if(leap(y)==true)
			{
				d++;
			}
			d%=7;
			if(d==0&&given==leap(y))
			{
				System.out.println(y);
				break;
			}
		}
	}
	static boolean leap(int y) {
		return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);
	}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class SameCalender
{
	boolean leap(int y){
		if(y%400==0||(y%4==0&&y%100!=0))
		  return true;
		else return false;
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		int y;
		Scanner s= new Scanner(System.in);
		y=s.nextInt();
		SameCalender c=new SameCalender();
		boolean a=c.leap(y);
		int d=0,x;
		do{
			d++;
			if(c.leap(y))
			   d++;
			 y++;
			 d=d%7;
			 if(c.leap(y)!=a)
			   x=1;
			 else x=0;
		}while(d>0||x==1);

			System.out.println(y);
		}
	}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author evgen
 */
public class class1 {
    public static void main(String args[])
{InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int god=in.nextInt();
        boolean cod=false;
        int y=0;
        if(!((god%4==0&&god%100!=0)||god%400==0)){
        while(!cod)
        {
        if((god%4==0&&god%100!=0)||god%400==0){y+=366;}
        else{y+=365;}

        god++;
        if(y%7==0&&!((god%4==0&&god%100!=0)||god%400==0)){cod=true;}
        }   }

        if(((god%4==0&&god%100!=0)||god%400==0)&&!cod)
        {
         while(!cod)
        {
        if((god%4==0&&god%100!=0)||god%400==0){y+=366;}
        else{y+=365;}

        god++;
        if(y%7==0&&((god%4==0&&god%100!=0)||god%400==0)){cod=true;}
        }
        }
out.print(god);
        out.close();}
static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
}}

import java.io.*;
import java.util.*;
/**
 *
 * @author Sourav Kumar Paul (spaul100)
 * NIT Silchar
 */

public class SolveB {

    public static Reader in;
    public static PrintWriter out;
    public static long mod = 1000000007;
    public static long inf = 100000000000000000l;
    public static long fac[],inv[];
    public static int union[];

    public static void solve(){
        int n = in.nextInt();
        boolean flag = leap(n);
        int ctr =0;
        while(true)
        {
            ctr++;
            if(leap(n))
            {
              //  out.println("cd "+n);
                ctr++;
            }
            ctr %=7;
            n++;
            if(ctr ==0 && flag == leap(n))
                break;

        }
        out.println(n);
    }

    private static boolean leap(int n) {
       if(n%400==0)
           return true;
       else if(n%4==0 && n%100 !=0)
           return true;
       else
           return false;
    }

/**
 *  ############################### Template ################################
 */

    public static class Pair implements Comparable{
        int x,y;

        Pair(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
        @Override
        public int compareTo(Object o)
        {
            Pair pp = (Pair)o;
            if(pp.x == x)
                return 0;
            else if (x>pp.x)
                return 1;
            else
                return -1;
        }
    }

    public static void init()
    {
        for(int i=0; i<union.length; i++)
            union[i] = i;
    }
    public static int find(int n)
    {
        return (union[n]==n)?n:(union[n]=find(union[n]));
    }
    public static void unionSet(int i ,int j)
    {
        union[find(i)]=find(j);
    }
    public static boolean connected(int i,int j)
    {
        return union[i]==union[j];
    }

    public static long gcd(long a, long b) {
        long x = Math.min(a,b);
        long y = Math.max(a,b);
        while(x!=0)
        {
            long temp = x;
            x = y%x;
            y = temp;
        }
        return y;
    }

    public static long modPow(long base, long exp, long mod) {
        base = base % mod;
        long result =1;
        while(exp > 0)
        {
            if(exp % 2== 1)
            {
                result = (result * base) % mod;
                exp --;
            }
            else
            {
                base = (base * base) % mod;
                exp = exp >> 1;
            }

        }
        return result;
    }

    public static void cal()
    {
        fac = new long[1000005];
        inv = new long[1000005];
        fac[0]=1;
        inv[0]=1;
        for(int i=1; i<=1000000; i++)
        {
            fac[i]=(fac[i-1]*i)%mod;
            inv[i]=(inv[i-1]*modPow(i,mod-2,mod))%mod;
        }
    }
    public static long ncr(int n, int r)
    {
        return (((fac[n]*inv[r])%mod)*inv[n-r])%mod;
    }

    SolveB() throws IOException {
	in = new Reader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
	solve();
        out.flush();
	out.close();
    }

    public static void main(String args[]) {
	new Thread(null, new Runnable() {
            public void run() {
                try {
                    new SolveB();
		} catch (Exception e) {
                    e.printStackTrace();
		}
            }
	}, "1", 1 << 26).start();
    }

    public static class Reader {
        public BufferedReader reader;
        public StringTokenizer st;

        public Reader(InputStreamReader stream) {
            reader = new BufferedReader(stream);
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public String nextLine() throws IOException{
            return reader.readLine();
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }

    }
}

import java.util.*;

public class HelloWorld {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		int counter = 0;
		int ya = 0;
		while(true) {
			if(isLeap(n + ya)) {
				counter += 2;
				ya++;
			}
			else {
				counter ++ ;
				ya++;
			}
			if(counter % 7 == 0) {
			    if((isLeap(n) && isLeap(n + ya)) || (!isLeap(n) && !isLeap(n + ya))) {
				    ans = n + ya;
				    break;
			    }
			}
		}
		System.out.println(ans);
	}

	public static boolean isLeap(int n) {
	    return n%400 == 0 || (n%4 == 0 && n%100 != 0);
	}
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class B {
	int y;

	public boolean isLeap(int y){
		if(y % 400 == 0)return true;
		if(y % 4 == 0 && y % 100 != 0)return true;
		return false;
	}

	public void solve() {
		y = nextInt();
		int week = 0;
		for(int i = y + 1;;i++){

			if(isLeap(i)){
				week = ((week + 366) % 7);
			}else{
				week = ((week + 365) % 7);
			}

			if(week == 0){
				if(isLeap(y) == isLeap(i)){
					out.println(i);
					break;
				}
			}
		}
		out.println();
	}

	public static void main(String[] args) {
		out.flush();
		new B().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

import java.util.*;
import java.math.*;
public class Udhan264 {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int t=0;
        int k=0;
        int a2=n%4;
         int b2=n%100;
         int c2=n%400;
         if(((a2==0)&&(b2!=0))||(c2==0)){
           k=1;
         }else{
           k=0;
         }

        for(int x=(n+1);;x++){
         int a=x%4;
         int b=x%100;
         int c=x%400;
         int u=0;
         if(((a==0)&&(b!=0))||(c==0)){
           u=1;
           t=t+2;
         }else{
             u=0;
           t=t+1;
         }
         if(((t%7)==0)&&(u==k)){
          System.out.println(x);
          return;
         }
        }
    }
}

import java.util.Scanner;

/**
 * Created by igarus on 13.06.2016.
 */
public class CF_B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int y = scanner.nextInt();
        int d = 0;
        boolean isLeap = isLeapYear(y);
        for (int i = 1; i < 1000; i++) {
            int ny = y + i;
            if (isLeapYear(ny))
                d += 366 % 7;
            else
                d += 365 % 7;
            if (d % 7 == 0 && isLeap == isLeapYear(ny)) {
                System.out.println(ny);
                break;
            }
        }
    }

    public static boolean isLeapYear(int y) {
        return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TheSameCalendar {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int y = Integer.parseInt(br.readLine());

		int day = 1;
		boolean leapOriginal = isLeap(y);
		boolean leapCurrent = leapOriginal;

		do{
			y++;
			leapCurrent = isLeap(y);
			if(leapCurrent){
				day += 2;
			}else{
				day++;
			}
			day = day%7;
		}while(day != 1 || leapOriginal != leapCurrent);

		System.out.println(y);
	}

	public static boolean isLeap(int y){
		if(y % 400 == 0){
			return true;
		}else if(y % 4 == 0 && y % 100 != 0){
			return true;
		}else{
			return false;
		}
	}
}

import java.util.Scanner;

	public class Solution
	{

		public static boolean isLeapYear(int year)
		{
			return(year%400==0 ||(year%4==0 && year%100!=0));
		}

		public static void main(String[] args)
		{
			Scanner sc=new Scanner(System.in);
			int year=sc.nextInt();
			int idx=0;
			boolean isStartLeap=isLeapYear(year);
			int y=year;
			boolean isCurrLeap=isLeapYear(y);

			do
			{
				if(isCurrLeap)
				{
					idx+=2;
				}else
				{
					idx+=1;
				}
				idx%=7;
				y++;
				isCurrLeap=isLeapYear(y);

			}while(isCurrLeap!=isStartLeap||idx!=0);
			System.out.println(y);
		}

	}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    //---------------------------------------------------------------------------

    static boolean f(int n) {
        if (n % 400 == 0) {
            return true;
        }
        if (n % 4 == 0 && n % 100 != 0) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        //-----------------------------------------------------------------------
        int n = in.nextInt();
        boolean fn = f(n);
        int x = 0;
        for (int i = n + 1; i < 10000001; i++) {
            if (f(i)) {
                x++;
            }
            x++;
            if (x % 7 == 0 && fn == f(i)) {
                out.println(i);
                break;
            }
        }
        //-----------------------------------------------------------------------
        out.close();
    }
    //---------------------------------------------------------------------------

    static class Pair implements Comparator {

        int first, second;

        public Pair() {

        }

        public Pair(int f, int s) {
            this.first = f;
            this.second = s;
        }

        @Override
        public int compare(Object o1, Object o2) {
            Pair p1 = (Pair) o1;
            Pair p2 = (Pair) o2;
            int ret = -Integer.compare(p1.first, p2.first);
            if (ret == 0) {
                ret = -Integer.compare(p1.second, p2.second);
            }
            return ret;
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char[] nextCharArray() {
            return next().toCharArray();
        }

        public boolean hasNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String s = reader.readLine();
                    if (s == null) {
                        return false;
                    }
                    tokenizer = new StringTokenizer(s);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }

        public void skipLine() {
            try {
                tokenizer = null;
                reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class thesamecalendar {

    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter w = new PrintWriter(System.out);

        //January 1, 1000 is a wednesday
        //365%7 + 1 == 2 so January 1, 1001 would normally be thursday.

        int[] startDays = new int[110000]; //0 for monday 1 for tuesday..... 5 for sat 6 for sun
        int currentDay = 2;
        startDays[1000] = 2;
        for (int i = 1001; i < startDays.length; i++) {
            currentDay++;
            if (leapYear(i - 1)) {
                currentDay++;
            }
            currentDay %= 7;
            startDays[i] = currentDay;
        }

        int n = Integer.parseInt(r.readLine());

        for (int i = n + 1; i < 110000; i++) {
            if (startDays[i] == startDays[n] && leapYear(i) == leapYear(n)) {
                w.println(i);
                w.flush();
                break;
            }
        }
    }

    public static boolean leapYear(int n) {
        if (n % 400 == 0) {
            return true;
        } else if (n % 4 == 0 && n % 100 != 0) {
            return true;
        }
        return false;
    }

}

import java.io.*;
import java.math.*;
import java.time.LocalDate;
import java.time.Month;
import java.util.*;

/**
 *
 * @author Saju
 *
 */

public class Main {

    private static int dx[] = { 1, 0, -1, 0 };
    private static int dy[] = { 0, -1, 0, 1 };

    private static final long INF = Long.MAX_VALUE;
    private static final int INT_INF = Integer.MAX_VALUE;
    private static final long NEG_INF = Long.MIN_VALUE;
    private static final int NEG_INT_INF = Integer.MIN_VALUE;
    private static final double EPSILON = 1e-10;

    private static final long MAX = (long) 1e12;

    private static final long MOD = 100000007;

    private static final int MAXN = 100;
    private static final int MAXA = 2000007;
    private static final int MAXLOG = 22;
    private static final double PI = Math.acos(-1);

	public static void main(String[] args) throws IOException {

		InputReader in = new InputReader(System.in);
//		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

//         InputReader in = new InputReader(new FileInputStream("src/test.in"));
//         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));

/*

*/

		int year = in.nextInt();
		LocalDate ld = LocalDate.of(year, Month.JANUARY, 1);
		int first= ld.getDayOfWeek().getValue();
		LocalDate ld1 = LocalDate.of(year, Month.DECEMBER, 31);
		int last = ld1.getDayOfWeek().getValue();

		for(int i = 1; i <= 400; i++) {
			LocalDate ld2 = LocalDate.of(year + i, Month.JANUARY, 1);
			int first1= ld2.getDayOfWeek().getValue();
			LocalDate ld3 = LocalDate.of(year + i, Month.DECEMBER, 31);
			int last1 = ld3.getDayOfWeek().getValue();
			if(first == first1 && last == last1) {
				out.println((year + i));
				break;
			}

		}

//		Calendar gc = new GregorianCalendar();
//		int year = in.nextInt();
//		gc.set(Calendar.YEAR, year);
//        gc.set(Calendar.MONTH, 0);
//        gc.set(Calendar.DAY_OF_MONTH, 1);
//        int first = gc.get(Calendar.DAY_OF_WEEK);
//        gc.set(Calendar.MONTH, 11);
//        gc.set(Calendar.DAY_OF_MONTH, 31);
//        int last = gc.get(Calendar.DAY_OF_WEEK);
//        System.out.println(first + " " + last);
//		for(int i = 1; i <= 400; i++) {
//			gc.set(Calendar.YEAR, year + i);
//	        gc.set(Calendar.MONTH, 0);
//	        gc.set(Calendar.DAY_OF_MONTH, 1);
//	        int first1 = gc.get(Calendar.DAY_OF_WEEK);
//	        gc.set(Calendar.MONTH, 11);
//	        gc.set(Calendar.DAY_OF_MONTH, 31);
//	        int last1 = gc.get(Calendar.DAY_OF_WEEK);
//	        if(first == first1 && last == last1) {
//	        	out.println(year + i);
//	        	break;
//	        }
//	        if(i == 6) {
//	        	System.out.println(first1 + " " + last1);
//	        }
//		}

		in.close();
		out.flush();
		out.close();
		System.exit(0);
	}

	/*
	 * return the number of elements in list that are less than or equal to the val
	 */
	private static long upperBound(List<Long> list, long val) {
		int start = 0;
		int len = list.size();
		int end = len - 1;
		int mid = 0;

		while (true) {
			if (start > end) {
				break;
			}
			mid = (start + end) / 2;
			long v = list.get(mid);
			if (v == val) {
				start = mid;
				while(start < end) {
					mid = (start + end) / 2;
					if(list.get(mid) == val) {
						if(mid + 1 < len && list.get(mid + 1) == val) {
							start = mid + 1;
						}
						else {
							return mid + 1;
						}
					}
					else {
						end = mid - 1;
					}
				}
				return start + 1;
			}
			if (v > val) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
		}
		if (list.get(mid) < val) {
			return mid + 1;
		}
		return mid;
	}

	private static boolean isPalindrome(String str) {
		StringBuilder sb = new StringBuilder();
		sb.append(str);
		String str1 = sb.reverse().toString();
		return str.equals(str1);
	}

	private static String getBinaryStr(long n, int j) {
		String str = Long.toBinaryString(n);
		int k = str.length();
		for (int i = 1; i <= j - k; i++) {
			str = "0" + str;
		}

		return str;
	}

	private static long modInverse(long r) {
		return bigMod(r, MOD - 2, MOD);
	}

	private static long bigMod(long n, long k, long m) {

        long ans = 1;
        while (k > 0) {
            if ((k & 1) == 1) {
                ans = (ans * n) % m;
            }
            n = (n * n) % m;
            k >>= 1;
        }
        return ans;
    }

	private static long ceil(long n, long x) {
		long div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
	}

    private static int ceil(int n, int x) {
        int div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
    }

    private static int abs(int x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static double abs(double x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static long abs(long x) {
        if(x < 0) {
            return -x;
        }
        return x;
    }

    private static int lcm(int a, int b) {
        return (a * b) / gcd(a, b);
    }

    private static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static long gcd(long a, long b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static int log(long x, int base) {
        return (int) (Math.log(x) / Math.log(base));
    }

    private static long min(long a, long b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static int min(int a, int b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static long max(long a, long b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static int max(int a, int b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());

                }
            } catch (IOException e) {
                return null;
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = null;
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public boolean hasNext() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (Exception e) {
                return false;
            }
            return true;
        }

        public int[] nextIntArr(int n) {
        	int arr[] = new int[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr(int n) {
        	long arr[] = new long[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public int[] nextIntArr1(int n) {
        	int arr[] = new int[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr1(int n) {
        	long arr[] = new long[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public void close() {
        	try {
        		if(reader != null) {
        			reader.close();
        		}
        	}
        	catch(Exception e) {

        	}

        }
    }

}

import java.util.Scanner;

public class SameCalendar {
    static boolean isLeap(long year) {
        if ( (year % 400 == 0) || ( year % 4 == 0 && year % 100 != 0) ) return true;
        return false;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long year = scanner.nextLong();
        boolean isLeap = isLeap(year);
        boolean _isLeap = false;
        int leapCount = 0;
        do {
            _isLeap = isLeap(year);
            if (_isLeap) leapCount += 2;
            else leapCount++;
            year++;
            _isLeap = isLeap(year);
            leapCount = leapCount%7;
            if (leapCount == 0 && (isLeap == _isLeap)) {
                break;
            }

        }while (true);

        System.out.println(year);
        scanner.close();
    }
}

import java.io.*;
import java.util.*;

/**
 * @author Alexander Tsupko (alexander.tsupko[at]outlook.com) (c) All rights reserved, June 14, 2016.
 */
public class B {
    private static class Solve {
        private int FIRST_DAY = 1;
        private int FIRST_MONTH = 1;

        private void solve(int testNumber, InputReader in, PrintWriter out) {
//            long startTime = System.nanoTime();

            int year = in.nextInt();

            int firstDayWhichDayOfTheWeek = whichDayOfTheWeek(FIRST_DAY, FIRST_MONTH, year);
            int lastDayWhichDayOfTheWeek;
            if (isLeap(year)) {
                lastDayWhichDayOfTheWeek = firstDayWhichDayOfTheWeek + 1;
            } else {
                lastDayWhichDayOfTheWeek = firstDayWhichDayOfTheWeek;
            }

            int firstDayOfThisYearWhichDayOfTheWeek;
            int lastDayOfThisYearWhichDayOfTheWeek;
            do {
                year++;
                firstDayOfThisYearWhichDayOfTheWeek = whichDayOfTheWeek(FIRST_DAY, FIRST_MONTH, year);
                if (isLeap(year)) {
                    lastDayOfThisYearWhichDayOfTheWeek = firstDayOfThisYearWhichDayOfTheWeek + 1;
                } else {
                    lastDayOfThisYearWhichDayOfTheWeek = firstDayOfThisYearWhichDayOfTheWeek;
                }
            } while (firstDayOfThisYearWhichDayOfTheWeek != firstDayWhichDayOfTheWeek
                    || lastDayOfThisYearWhichDayOfTheWeek != lastDayWhichDayOfTheWeek);

            out.println(year);

//            long estimatedTime = System.nanoTime() - startTime;
//            out.printf(Locale.US, "%.1f ms\n", estimatedTime/1e6);
        }

        private boolean isLeap(int year) {
            return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
        }

        private int whichDayOfTheWeek(int day, int month, int year) {
            int m = month + 10;
            int y = --year % 100;
            int c = year / 100;
            int W = (day + (13 * m - 1) / 5 + y + y / 4 + c / 4 - 2 * c) % 7;
            W = W < 0 ? W + 7 : W;
            return W;
        }
    }

    private static class InputReader {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        private InputReader(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 32768);
        }

        private void close() throws IOException {
            bufferedReader.close();
        }

        private String nextLine() {
            try {
                return bufferedReader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        private String next() {
            while (stringTokenizer == null || !stringTokenizer.hasMoreTokens())
                stringTokenizer = new StringTokenizer(nextLine());
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solve solve = new Solve();
        solve.solve(1, in, out);
//        int testCount = Integer.parseInt(in.next());
//        for (int i = 1; i <= testCount; i++) solve.solve(i, in, out);
        in.close();
        out.close();
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int y = in.nextInt();
            int nextY = y;
            long sum = 0;
            while (true) {
                sum += (leap(nextY) ? 1 : 0) + 365;
                nextY++;
                if (sum % 7 == 0 && leap(y) == leap(nextY)) {
                    out.println(nextY);
                    return;
                }
            }
        }

        boolean leap(int y) {
            return ((y % 400 == 0) || (y % 4 == 0 && y % 100 != 0));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;

public class Second{
	static long mod=1000000007;
	static int leap(int n)
	{
		int f=0;
		if (n%4!=0)
		{
		//then (it is a common year)
		f=0;
		}
	else if (n%100!=0)
		{
		//then (it is a leap year)
		f=1;
		}
	else if (n%400!=0)
		{
		//then (it is a common year)
		f=0;
		}
	else {
		//(it is a leap year)
		f=1;
	}
		return f;
	}
    public static void main(String[] args) throws Exception{
    	 InputReader in = new InputReader(System.in);
    	PrintWriter pw=new PrintWriter(System.out);

    	//int t=in.readInt();
        //	while(t-->0)
        	//{

    	int n=in.readInt();
    	int f=leap(n);
    	int s=0;
    	if(f==1)
    	{
    		s=366;
    	}
    	else
    		s=365;
    	int ans=n+1;
    	while((s%7!=0)||(leap(ans)!=f))
    	{
    		s+=365;
    		if(leap(ans)==1)
    			s++;
    		ans++;
    	}
    	pw.println(ans);

    	pw.close();
    }

public static long gcd(long x,long y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}

public static int gcd(int x,int y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}
public static int abs(int a,int b)
{
	return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
	return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
public static int min(int a,int b)
{
	if(a>b)
		return b;
	else
		return a;
}
public static long max(long a,long b)
{
	if(a>b)
		return a;
	else
		return b;
}
public static long min(long a,long b)
{
	if(a>b)
		return b;
	else
		return a;
}

public static long pow(long n,long p,long m)
{
	 long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
}
public static long pow(long n,long p)
{
	long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    p >>=1;
	    n*=n;
	}
	return result;

}
static class Pair implements Comparable<Pair>
{
	int a,b;
	Pair (int a,int b)
	{
		this.a=a;
		this.b=b;
	}

	public int compareTo(Pair o) {
		// TODO Auto-generated method stub
		if(this.a!=o.a)
		return Integer.compare(this.a,o.a);
		else
			return Integer.compare(this.b, o.b);
		//return 0;
	}
	public boolean equals(Object o) {
        if (o instanceof Pair) {
            Pair p = (Pair)o;
            return p.a == a && p.b == b;
        }
        return false;
    }
    public int hashCode() {
        return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
    }
}

static long sort(int a[],int n)
{  	int b[]=new int[n];
	return mergeSort(a,b,0,n-1);}
static long mergeSort(int a[],int b[],long left,long right)
{ long c=0;if(left<right)
 {   long mid=left+(right-left)/2;
	 c= mergeSort(a,b,left,mid);
	 c+=mergeSort(a,b,mid+1,right);
	 c+=merge(a,b,left,mid+1,right); }
	return c;	 }
static long merge(int a[],int  b[],long left,long mid,long right)
{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right)
{ if(a[i]<=a[j]) {b[k++]=a[i++]; }
else	{ b[k++]=a[j++];c+=mid-i;}}
while (i <= (int)mid - 1)   b[k++] = a[i++];
while (j <= (int)right) b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
	a[i] = b[i];  return c;  }

   static  class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }

//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	//StringBuilder sb=new StringBuilder("");
	 //InputReader in = new InputReader(System.in);
	//PrintWriter pw=new PrintWriter(System.out);
	//String line=br.readLine().trim();

	//int t=Integer.parseInt(br.readLine());
  //	while(t-->0)
  	//{
  	//int n=Integer.parseInt(br.readLine());
	//long n=Long.parseLong(br.readLine());
	//String l[]=br.readLine().split(" ");
  //int m=Integer.parseInt(l[0]);
	//int k=Integer.parseInt(l[1]);
	//String l[]=br.readLine().split(" ");
	//l=br.readLine().split(" ");
	/*int a[]=new int[n];
	for(int i=0;i<n;i++)
	{
		a[i]=Integer.parseInt(l[i]);
	}*/
	   //System.out.println(" ");

	//}
}

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        int n = parseInt(in.readLine());

        if(isLeap(n)) {
            int cur = 0;
            n++;
            if(isLeap(n)) cur = (cur+2)%7;
            else cur = (cur+1)%7;

            while(!isLeap(n) || cur != 0) {
                n++;
                if(isLeap(n)) cur = (cur+2)%7;
                else cur = (cur+1)%7;
            }

            System.out.println(n);
        } else {
            int cur=0;
            n++;
            if(isLeap(n)) cur = (cur+2)%7;
            else cur = (cur+1)%7;

            while(isLeap(n) || cur != 0) {
                n++;
                if(isLeap(n)) cur = (cur+2)%7;
                else cur = (cur+1)%7;
            }

            System.out.println(n);
        }
    }

    static boolean isLeap(int n) {
        return n%400==0 || (n%4==0 && n%100!=0);
    }
}

import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int y = sc.nextInt();
        boolean leap = isLeap(y);
        int originalRes = leap ? 2 : 1;
        int res = originalRes;
        for (int i = y + 1;; i++) {
            if (isLeap(i))
                res = (res + 2) % 7;
            else
                res = (res + 1) % 7;
            if (isLeap(i) == leap && originalRes == res) {
                System.out.println(i);
                return;
            }
        }
    }

    private static boolean isLeap(int y) {
        if (y % 400 == 0)
            return true;
        else if (y % 100 == 0)
            return false;
        else if (y % 4 == 0)
            return true;
        else
            return false;
    }
}

import java.io.*;
import java.util.*;

public class Send {
    private static InputReader in;

    public static void main(String[] args) {
        in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out, true);

        int y = in.nextInt();
        int m = 0;
        for (int i = y + 1; i < y + 100; i++) {
            m += days(i) % 7;
            if (m % 7 == 0 && isW(y) == isW(i)) {
                System.out.println(i);
                break;
            }
        }
    }

    static int days(int y) {
        if (isW(y)) {
            return 366;
        }
        return 365;
    }

    static boolean isW(int y) {
        return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);
    }

    private static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

        import java.util.*;
        import java.io.*;
        /**
         *
         * @author umang
         */

        public class B678 {

                public static int leap(long x){
					if(x%400==0 || (x%4==0 && x%100!=0)) return 2;
					else return 1;
                }

                public static void main(String[] args) {

                        InputReader in = new InputReader(System.in);
                        PrintWriter w = new PrintWriter(System.out);

                        long n = in.nextLong();
                        long x = n;
                        int t=0;
                        while(leap(x)!=leap(n)||t%7!=0||t==0){
							t+=leap(n);
							n++;
						}

                        w.println(n);

                        w.close();
                }

                static class InputReader {

                        private final InputStream stream;
                        private final byte[] buf = new byte[8192];
                        private int curChar, snumChars;
                        private SpaceCharFilter filter;

                        public InputReader(InputStream stream) {
                                this.stream = stream;
                        }

                        public int snext() {
                                if (snumChars == -1)
                                        throw new InputMismatchException();
                                if (curChar >= snumChars) {
                                        curChar = 0;
                                        try {
                                                snumChars = stream.read(buf);
                                        } catch (IOException e) {
                                                throw new InputMismatchException();
                                        }
                                        if (snumChars <= 0)
                                                return -1;
                                }
                                return buf[curChar++];
                        }

                        public int nextInt() {
                                int c = snext();
                                while (isSpaceChar(c))
                                        c = snext();
                                int sgn = 1;
                                if (c == '-') {
                                        sgn = -1;
                                        c = snext();
                                }
                                int res = 0;
                                do {
                                        if (c < '0' || c > '9')
                                                throw new InputMismatchException();
                                        res *= 10;
                                        res += c - '0';
                                        c = snext();
                                } while (!isSpaceChar(c));
                                return res * sgn;
                        }

                        public long nextLong() {
                                int c = snext();
                                while (isSpaceChar(c))
                                        c = snext();
                                int sgn = 1;
                                if (c == '-') {
                                        sgn = -1;
                                        c = snext();
                                }
                                long res = 0;
                                do {
                                        if (c < '0' || c > '9')
                                                throw new InputMismatchException();
                                        res *= 10;
                                        res += c - '0';
                                        c = snext();
                                } while (!isSpaceChar(c));
                                return res * sgn;
                        }

                        public int[] nextIntArray(int n) {
                                int a[] = new int[n];
                                for (int i = 0; i < n; i++)
                                        a[i] = nextInt();
                                return a;
                        }

                        public String readString() {
                                int c = snext();
                                while (isSpaceChar(c))
                                        c = snext();
                                StringBuilder res = new StringBuilder();
                                do {
                                        res.appendCodePoint(c);
                                        c = snext();
                                } while (!isSpaceChar(c));
                                return res.toString();
                        }

                        public boolean isSpaceChar(int c) {
                                if (filter != null)
                                        return filter.isSpaceChar(c);
                                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
                        }

                        public interface SpaceCharFilter {
                                public boolean isSpaceChar(int ch);
                        }
                }
        }

import java.util.*;

public class Main {

	private static Scanner scan = new Scanner(System.in);

	public static void main(String [] args) {

		int y = scan.nextInt();
		int x = 0;
		for(int i=y+1; ; i++) {
			x++;
			if(isLeap(i) == true) x++;
			x %= 7;
			if(x == 0 && isLeap(y) == isLeap(i)) {
				System.out.println(i);
				break;
			}
		}

	}

	static boolean isLeap(int y) {
		if(y%400 == 0) return true;
		if(y%100 == 0) return false;
		if(y%4 == 0) return true;
		return false;
	}

}

import java.util.*;

public class Main {
    static Scanner in = new Scanner(System.in);
    static boolean check(int x) {
        if (x % 400 == 0 || (x % 4 == 0 && x % 100 != 0))
            return true;
        return false;
    }
    public static void main(String[] args) {
        int x = in.nextInt();
        int y = x + 1;
        int[] month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int sum = 0;
        while (true) {
            if (check(y))
                sum += 366;
            else
                sum += 365;
            if (check(x) == check(y)) {
                if (sum % 7 == 0) {
                    System.out.println(y);
                    return ;
                }
            }
            y++;
        }
    }
}

import java.io.*;
import java.util.*;

public class A {
	public static void main (String[] args) { new A(); }

	public A() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int y = fs.nextInt();

		int cur = y+1, delta = 0;
		while(true) {
			int prev = cur-1;
			if(isLeap(prev)) {
				delta = (delta + 2) % 7;
			}
			else {
				delta = (delta + 1) % 7;
			}
			if(delta == 0 && isLeap(y) == isLeap(cur)) break;
			cur++;
		}
		out.println(cur);

		out.close();
	}

	boolean isLeap(int year) {
		if(year % 400 == 0) return true;
		if(year % 4 == 0 && year % 100 != 0) return true;
		return false;
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}

	}

}

/*
 * The MIT License
 *
 * Copyright 2016 Mouad NACIRI <mouadnaciri1@gmail.com>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;

/**
 *
 * @author NACIRI Mouad <mouadnaciri1@gmail.com>
 * @version 1.5.2
 */

public class CF {
    /* VIP, DON'T TOUCH!! */
    static StringTokenizer ST;
    static BufferedReader IN;
    static PrintStream O, E;
    static {
        IN = new BufferedReader(new InputStreamReader(System.in));
        O = System.out;
        E = System.err;
    }
    /*
    int   2147483647            /  -2147483648
    long  9223372036854775807L  /  -9223372036854775808L
    */
    public static void main(String[] ag) throws IOException {
        int n = ni();
        int ret = 0, y = n;
        boolean cls = il(y);

        while(true) {
            ret += 365 + (il(++n) ? 1 : 0);
            ret %= 7;
            if(ret == 0 && cls == il(n)) {
                O.println(n);
                break;
            }
        }
        cAll();
    }

    static long gcdl(long a, long b) { return b == 0 ? a : gcdl(b, a % b); }
    static long lcml(long a, long b) { return a * (b / gcdl(a, b)); }
    static boolean il(int n) {  return n % 400 == 0 || (n % 4 == 0 && n % 100 != 0); }

    //IO stuff...
    static void ll() { ST = new StringTokenizer(nlnt()); }
    static void ll(String del) { ST = new StringTokenizer(nlnt(), del); }
    static void ll(String s, String del) { ST = new StringTokenizer(s, del); }
    static void lll(String s) { ST = new StringTokenizer(s); }

    static int tlen() { return ST == null ? 0 : ST.countTokens(); }
    static boolean hn() { return ST != null && ST.hasMoreTokens(); }
    static String n() {
        if(!hn()) { ll(); }
        return ST.nextToken();
    }
    static String nln() {
        String l = null;
        try {
            while((l = IN.readLine()) != null && l.trim().length() == 0) {}
        } catch(IOException e) { }
        ST = null;
        return l;
    }
    static String nlnt() {
        String l = null;
        try {
            while((l = IN.readLine()) != null && (l = l.trim()).length() == 0) {}
        } catch(IOException e) { }
        ST = null;
        return l;
    }
    static boolean nbl() { return Boolean.parseBoolean(n()); }
    static byte nb() { return Byte.parseByte(n()); }
    static byte nb(int radix) { return Byte.parseByte(n(), radix); }
    static double nd() { return Double.parseDouble(n()); }
    static float nf() { return Float.parseFloat(n()); }
    static int ni() { return Integer.parseInt(n()); }
    static int ni(int radix) { return Integer.parseInt(n(), radix); }
    static long nl() { return Long.parseLong(n()); }
    static long nl(int radix) { return Long.parseLong(n(), radix); }
    static short ns() { return Short.parseShort(n()); }
    static short ns(int radix) { return Short.parseShort(n(), radix); }

    static void cAll() throws IOException { IN.close(); }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author wannabe
 */
public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskB {

		public void solve(int testNumber, Scanner in, PrintWriter out) {
			int n = in.nextInt();
			int day = 1;
			boolean isLeap = isLeap(n);
			do {
				n++;
				day += isLeap(n) ? 2 : 1;
				if (day > 7) {
					day -= 7;
				}
				if (day == 1 && isLeap == isLeap(n)) {
					break;
				}
			} while (true);

			out.print(n);
		}

		private boolean isLeap(int n) {
			return n % 400 == 0 || (n % 4 == 0 && n % 100 != 0);
		}

	}
}

import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
        String next() { while (st == null || !st.hasMoreElements()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (IOException e) { e.printStackTrace(); } }
                return st.nextToken();
            }

        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }

        String nextLine() {
            String str = "";
            try { str = br.readLine(); }
            catch (IOException e) { e.printStackTrace(); }
            return str;
        }
    }

    static boolean isLeapYear(long n){
        if(n%4==0){
            if(n%400==0){
                return true;
            }else if(n%100==0){
                return false;
            }else{
                return true;
            }
        }
            return false;
    }

    public static void main(String[] args) throws IOException {
        FastReader ip = new FastReader();
        OutputStream output = System.out;
        PrintWriter out = new PrintWriter(output);
            long n = ip.nextLong();
            int p=0;
            int f=0;
            boolean ans=isLeapYear(n);
            while (true){
                if(isLeapYear(n)){
                    p+=2;
                }else{
                    p++;
                }
                p=p%7;
                n++;
                if(p==0 && ans==isLeapYear(n)){
                    break;
                }
            }
            out.print(n);
        out.close();
    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.lang.reflect.Array;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;

public class Main {
    public void exec() {
        int y = stdin.nextInt();
        LocalDate d1 = LocalDate.of(y, 1, 1);
        LocalDate d2 = d1.plusYears(1);
        while (true) {
            if (d1.getDayOfWeek() == d2.getDayOfWeek() && countDay(d1.getYear()) == countDay(d2.getYear())) break;
            d2 = d2.plusYears(1);
        }
        stdout.println(d2.getYear());
    }

    public int countDay(int year) {
        return LocalDate.of(year, 1, 1).plusYears(1).minusDays(1).getDayOfYear();
    }

    private static final Stdin stdin = new Stdin(System.in);
    private static final Stdout stdout = new Stdout();

    public static void main(String[] args) {
        try {
            new Main().exec();
        } finally {
            stdout.flush();
        }
    }

    public static class Stdin {
        private InputStream in;
        private byte[] buf;
        private int ptr;
        private int len;

        public Stdin(InputStream in) {
            this.in = in;
            this.buf = new byte[1024];
            this.ptr = 0;
            this.len = 0;
        }

        public String nextString() {
            StringBuilder sb = new StringBuilder();
            byte b;
            while ((b = read()) != -1) {
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }

        public int nextInt() {
            return (int)nextLong();
        }

        public double nextDouble() {
            return Double.parseDouble(nextString());
        }

        public long nextLong() {
            boolean negative = false;
            int x = 0;

            byte b = read();
            if (b == '-') {
                negative = true;
            } else {
                x += b-'0';
            }

            while ((b=read()) != -1) {
                x *= 10;
                x += b-'0';
            }

            return negative ? -x : x;
        }

        private byte read() {
            byte b = readByte();
            if (b == '\r') {
                readByte(); // LFを読み飛ばす
                return -1;
            } else if (b == '\n' || b == ' ') {
                return -1;
            } else {
                return b;
            }
        }

        private byte readByte(){
            if (len == ptr) {
                try {
                    ptr = 0;
                    len = in.read(buf);
                    if (len == -1) return -1;
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return buf[ptr++];
        }

        public String[] nextStringArray(int n) {
            String[] a = new String[n];
            for (int i = 0; i < n; i++) a[i] = nextString();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) a[i] = nextDouble();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }

    public static class Stdout {
        private PrintWriter stdout;

        public Stdout() {
            stdout =  new PrintWriter(System.out, false);
        }

        public void printf(String format, Object ... args) {
            String line = String.format(format, args);
            if (line.endsWith(System.lineSeparator())) {
                stdout.print(line);
            } else {
                stdout.println(line);
            }
        }

        public void println(Object ... objs) {
            String line = Arrays.stream(objs).map(Objects::toString).collect(Collectors.joining(" "));
            stdout.println(line);
        }

        public void printDebug(Object ... objs) {
            String line = Arrays.stream(objs).map(this::deepToString).collect(Collectors.joining(" "));
            stdout.printf("DEBUG: %s%n", line);
            stdout.flush();
        }

        private String deepToString(Object o) {
            if (o == null) {
                return "null";
            }

            // 配列の場合
            if (o.getClass().isArray()) {
                int len = Array.getLength(o);
                String[] tokens = new String[len];
                for (int i = 0; i < len; i++) {
                    tokens[i] = deepToString(Array.get(o, i));
                }
                return "{" + String.join(",", tokens) + "}";
            }

            return Objects.toString(o);
        }

        private void flush() {
            stdout.flush();
        }
    }
}

import java.util.*;
import java.io.*;

public class TheSameCalendar {
    public static InputReader in;
    public static PrintWriter out;

    public static final int MOD = (int) (1e9 + 7);

    public static void main(String[] args) {
	in = new InputReader(System.in);
	out = new PrintWriter(System.out);

	int y = in.nextInt();
	int yy = y + 1;
	for (int days = days(yy); !(days%7 == 0 && days(yy) == days(y)); yy++, days += days(yy));
	out.println(yy);
	out.close();
    }

    public static int days(int year) {
	if(year%400 == 0 || (year%4 == 0 && year%100 != 0)) {
	    return 366;
	}
	return 365;
    }

    static class Node implements Comparable<Node> {
	int next;
	int dist;

	public Node(int u, int v) {
	    this.next = u;
	    this.dist = v;
	}

	public void print() {
	    out.println(next + " " + dist + " ");
	}

	public int compareTo(Node that) {
	    return Integer.compare(this.next, that.next);
	}
    }

    static class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[8192];
	private int curChar, snumChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
	    this.stream = stream;
	}

	public int snext() {
	    if (snumChars == -1)
		throw new InputMismatchException();
	    if (curChar >= snumChars) {
		curChar = 0;
		try {
		    snumChars = stream.read(buf);
		} catch (IOException e) {
		    throw new InputMismatchException();
		}
		if (snumChars <= 0)
		    return -1;
	    }
	    return buf[curChar++];
	}

	public int nextInt() {
	    int c = snext();
	    while (isSpaceChar(c))
		c = snext();
	    int sgn = 1;
	    if (c == '-') {
		sgn = -1;
		c = snext();
	    }
	    int res = 0;
	    do {
		if (c < '0' || c > '9')
		    throw new InputMismatchException();
		res *= 10;
		res += c - '0';
		c = snext();
	    } while (!isSpaceChar(c));
	    return res * sgn;
	}

	public long nextLong() {
	    int c = snext();
	    while (isSpaceChar(c))
		c = snext();
	    int sgn = 1;
	    if (c == '-') {
		sgn = -1;
		c = snext();
	    }
	    long res = 0;
	    do {
		if (c < '0' || c > '9')
		    throw new InputMismatchException();
		res *= 10;
		res += c - '0';
		c = snext();
	    } while (!isSpaceChar(c));
	    return res * sgn;
	}

	public int[] nextIntArray(int n) {
	    int a[] = new int[n];
	    for (int i = 0; i < n; i++)
		a[i] = nextInt();
	    return a;
	}

	public String readString() {
	    int c = snext();
	    while (isSpaceChar(c))
		c = snext();
	    StringBuilder res = new StringBuilder();
	    do {
		res.appendCodePoint(c);
		c = snext();
	    } while (!isSpaceChar(c));
	    return res.toString();
	}

	public boolean isSpaceChar(int c) {
	    if (filter != null)
		return filter.isSpaceChar(c);
	    return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
	    public boolean isSpaceChar(int ch);
	}
    }
}

import java.util.Scanner;

/**
 * @author stran
 * @version 1.0 (14/06/2016).
 */
public class P678B_SameCalendar {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int y = scanner.nextInt(),
            next = y, sumOdd = (isLeapYear(next) ? 2 : 1);
        boolean yLeap = isLeapYear(y),
            nextLeap;

        do {
            next++;
            sumOdd += (isLeapYear(next) ? 2 : 1);
            nextLeap = isLeapYear(next + 1);
        } while (sumOdd % 7 != 0 || nextLeap != yLeap);

        System.out.println(next + 1);
    }

    private static boolean isLeapYear(int year) {
        return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
    }
}

import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    //    RRRRRRRRR            AAA             HHH     HHH     IIIIIIIIIIIII   LLL           //
    //    RR    RRR           AAAAA            HHH     HHH      IIIIIIIIIII    LLL           //
    //    RR   RRR           AAAAAAA           HHH     HHH          III        LLL           //
    //    RR  RRR           AAA   AAA          HHHHHHHHHHH          III        LLL           //
    //    RRRRRR           AAA     AAA         HHHHHHHHHHH          III        LLL           //
    //    RR  RRR         AAAAAAAAAAAAA        HHH     HHH          III        LLL           //
    //    RR    RRR      AAA         AAA       HHH     HHH      IIIIIIIIIII    LLLLLLLLLLLL  //
    //    RR     RRR    AAA           AAA      HHH     HHH     IIIIIIIIIIIII   LLLLLLLLLLLL  //
    ///////////////////////////////////////////////////////////////////////////////////////////

    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        int n=sc.i();
        int leap=n%400==0||(n%4==0&&n%100!=0)?1:0;
        int day=0;
        while(true)
        {
            n++;
            if(n%400==0||(n%4==0&&n%100!=0))
            day+=2;
            else
            day++;
            if(day%7==0)
            {
                if(n%400==0||(n%4==0&&n%100!=0))
                {
                  if(leap==1)
                  break;
                }
                else
                {
                    if(leap==0)
                    break;
                }
            }
        }
        System.out.println(n);
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class B {

	public static void main(String[] args) {
		try (Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)))) {
			System.out.println(solve(in.nextInt()));
		}
	}

	private static int solve(int y) {
		int d = 0, n = y;
		final boolean leap = leap(y);
		while (true) {
			n++;
			boolean l = leap(n);
			d += l ? 366 : 365;
			if (l == leap && d % 7 == 0) {
				return n;
			}
		}
	}

	private static boolean leap(int y) {
		return y % 400 == 0 || y % 4 == 0 && y % 100 != 0;
	}

}

import java.io.*;
import java.util.*;

public class Main {
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    boolean vis(int n) {
        return (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0));
    }

    void solve() throws IOException {
        int y = nextInt();
        int d = 0;
        int p = -1;
        for (int i = 0; ; i++) {
            if (!vis(i)) {
                d += 365;
            } else {
                d += 366;
            }
            d %= 7;
            if (i == y) {
                p = d;
            } else if (i > y && p == d && vis(i) == vis(y)) {
                out.println(i);
                return;
            }
        }
    }

    void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import static java.time.Year.isLeap;

/**
 * See CF678B
 *
 * @author Brian Yeicol Restrepo Tangarife
 */
public class CF678B {

	static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {

		int y = readInt();
		int days = 0;
		if (isLeap(y)) {
			while (true) {
				y++;
				boolean isLeap = isLeap(y);
				days += isLeap ? 2 : 1;
				if (days % 7 == 0 && isLeap) {
					break;
				}
			}
		} else {
			while (true) {
				y++;
				boolean isLeap = isLeap(y);
				days += isLeap ? 2 : 1;
				if (days % 7 == 0 && !isLeap) {
					break;
				}
			}
		}
		out.println(y);
		out.close();
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}

}

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private boolean useFiles = false;
    private String fileIn = "input.txt";
    private String fileOut = "output.txt";

    boolean isHigh(long y) {
        return y % 400 == 0 || y % 4 == 0 && y % 100 != 0;
    }

    void solve() throws IOException {

        long offset = 0;

        long y = nextLong();
        boolean firstHigh = isHigh(y);

        while (true) {

            y++;

            boolean high = isHigh(y);
            if (high) {
                offset += 366 % 7;
            } else {
                offset += 365 % 7;
            }

            offset %= 7;

            if (offset == 0 && firstHigh == high) {
                System.out.println(y);
                break;
            }

        }

    }

    void run() throws IOException {
        st = new StringTokenizer("");

        if (useFiles) {
            in = new BufferedReader(new FileReader(fileIn));
            out = new PrintWriter(new FileWriter(fileOut));
        } else {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }

        solve();

        in.close();
        out.close();
    }

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    public static void main(String[] args) throws java.lang.Exception {
        Reader pm =new Reader();
        //Scanner pm = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int t = 1;
        while(t-- > 0){
            long n = pm.nextInt();
            int fl = 0;
            int odd = 0;
            if(((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0))
                fl = 1;
            while(true){
                if(((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0)) {
                    odd+=2;
                    n++;
                } else {
                    odd++;
                    n++;
                }
                if(odd % 7 == 0){
                    if(fl == 1){
                        if(((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0)){
                            System.out.println(n);
                            return;
                        }
                        else
                            continue;
                    } else {
                        if(((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0)){
                            continue;
                        }else {
                            System.out.println(n);
                            return;
                        }

                    }

                }
            }
        }

    }

    static int countInRange(int arr[], int n, int x, int y) {
        // initialize result
        int count = 0;
        count = upperIndex(arr, n, y) -
                lowerIndex(arr, n, x) + 1;
        return count;
    }

    static int lowerIndex(int arr[], int n, int x) {
        int l = 0, h = n - 1;
        while (l <= h)
        {
            int mid = (l + h) / 2;
            if (arr[mid] >= x)
                h = mid - 1;
            else
                l = mid + 1;
        }
        return l;
    }

    // function to find last index <= y
    static int upperIndex(int arr[], int n, int y) {
        int l = 0, h = n - 1;
        while (l <= h)
        {
            int mid = (l + h) / 2;
            if (arr[mid] <= y)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }

    public static StringBuilder dec_to_bin(long n) {
        // decimal to binary upto 30 binaries
        if(n==0) {
            StringBuilder str=new StringBuilder("");
            for(int i=0;i<30;i++) {
                str.append("0");
            }
            return str;
        }
        StringBuilder str=new StringBuilder("");
        while(n!=0) {
            str.append(n%2L);
            n/=2L;
        }
        str=str.reverse();
        StringBuilder tmp_str=new StringBuilder("");
        int len=str.length();
        while(len!=30) {
            tmp_str.append("0");
            len++;
        }
        tmp_str.append(str);
        return tmp_str;
    }

    private static int binarySearchPM(int[] arr, int key){
        int n = arr.length;
        int mid = -1;
        int begin = 0,end=n;
        while(begin <= end){
            mid = (begin+end) / 2;
            if(mid == n){
                return n;
            }
            if(key < arr[mid]){
                end = mid-1;
            } else if(key > arr[mid]){
                begin = mid+1;
            } else {
                return mid;
            }
        }
        //System.out.println(begin+" "+end);
        return -begin; //expected Index
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.time.LocalDate;

public class BeautyCallendar {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter printWriter = new PrintWriter(System.out);
        int n = Integer.parseInt(br.readLine());
        LocalDate c = LocalDate.of(n, 1, 1);
        int i = n + 1;
        while (true){
            if (compare(c, c.plusYears(i - n))) {
                printWriter.print(i);
                break;
            }
            i++;
        }
        printWriter.flush();
        printWriter.close();
    }

    private static boolean compare(LocalDate c, LocalDate date) {
        if (c.isLeapYear() != date.isLeapYear()) {
            return false;
        }
        for (int i = 0; i < 12; ++i) {
            if(!c.plusMonths(i).getDayOfWeek().equals(date.plusMonths(i).getDayOfWeek())) {
                return false;
            }
        }
        return true;
    }
}

/* Author : Kishan Patel
 * From   : DAIICT
 */
import java.io.*;
import java.util.*;

public class Que2 {
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		boolean l=leap(n);
		int count=0;
		while(true){
			if(leap(n)){
				count+=2;
			}
			else{
				count+=1;
			}
			if(count%7==0 && leap(n+1)==l){
				break;
			}
			n++;
		}
		System.out.println(n+1);
	}

	static boolean leap(int x){
		if(x%400==0 || (x%4==0 && x%100!=0)){
			return true;
		}
		else{
			return false;
		}
	}
}

import java.util.*;

public class Solution {

    static boolean leapYear(int year) {
        return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
    }

    static int daysInYear(int year) {
        if (leapYear(year))
            return 366;
        return 365;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int candidate = n + 1;
        int shift = daysInYear(n) % 7;
        for (; leapYear(candidate) != leapYear(n) || shift != 0; candidate++) {
            shift = (shift + daysInYear(candidate)) % 7;
        }

        System.out.println(candidate);

    }
}

import java.util.Scanner;

public class Year {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int year = input.nextInt();
		int now = year;
		int day = (365+leap(year))%7;
		int leap = leap(year);
		while(leap!=leap(++now) || day!=0){
			day = (day+365+leap(now))%7;
		}
		System.out.println(now);
	}
	public static int leap(int y){
		if (y%400==0 || (y%4==0 && y%100!=0)){
			return 1;
		}
		return 0;
	}
}

import static java.lang.System.*;
import static java.lang.Math.*;
import java.io.*;
import java.util.*;
import java.math.*;

public class A {

    public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(System.in);
        int year = input.nextInt();
        int firstDay=3;
        int Day=3;
        int yearDay=0;
        int Days=0;
        for (int current = 1000; current < year+200; current++) {
            int days=365;
            if(current%4==0 && current%100!=0 || current%400==0){
                days++;
            }
            if(current==year){
                yearDay=Day;
                Days=days;
            }
            if(current>year && Day==yearDay && days==Days){
                out.println(current);
                break;
            }
            for(int j=365; j<=days; j++){
                Day=(Day+1)%7;
            }
        }
    }
}

import java.util.*;
import java.io.*;
//558A
public class TestClass{
	public static void main(String[] args) throws Exception{

		InputReader sc = new InputReader(System.in);
		PrintWriter wr = new PrintWriter(System.out);
		int y=sc.nextInt();
		int leap=0;

		int d=1;
		if(y%400==0||(y%4==0&&y%100!=0)){
			leap=1;
			d++;
		}
		for(int i=y+1;;i++){
			int flag=0;
			if(i%400==0||(i%4==0&&i%100!=0)){
				flag=1;
			}
			if(d%7==0&&flag==leap){
				System.out.println(i);
				return;
			}
			d++;
			if(i%400==0||(i%4==0&&i%100!=0)){
				d++;
			}
		}
	}
	public static int GCD(int value1, int value2)
    {
        while (value1 != 0 && value2 != 0)
        {
            if (value1 > value2)
                value1 %= value2;
            else
                value2 %= value1;
        }
        return Math.max(value1, value2);
    }
	public static long power(long a,long b)
	{
	    long ans=1;
	    while(b>0)
	    {
	        if(b%2==1)
	        {
	            ans*=a;
	            ans=ans%1000000007;
	        }
	        a*=a;
	        a=a%1000000007;
	        b/=2;
	    }
	    return ans%1000000007;
	}
}
class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	public int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	public long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	public void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	public void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}

}

import java.util.*;

/**
 * Created by m.shakhan on 20.06.2016.
 */
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int y = in.nextInt();
        boolean isLeap = y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
        int counter = 0;
        do {
            y++;
            if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
                counter += 2;
            } else {
                counter++;
            }
        } while (counter % 7 != 0 || isLeap != (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)));
        System.out.println(y);
    }
}

import java.util.Scanner;

public class ProblemB {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int start = 0;
		boolean isLeapYear = isLeapYear(n);
		for(int go = n+1; true; go++){
			int days = 365;
			if(isLeapYear(go)){
				days++;
			}
			start += days;
			start = start%7;
			if(start == 0 && isLeapYear(go) == isLeapYear){
				System.out.println(go);
				break;
			}
		}
	}

	private static boolean isLeapYear(int n) {
		if(n%4 != 0){
			return false;
		}
		if(n%400 == 0){
			return true;
		}
		if(n%100 == 0){
			return false;
		}
		return true;
	}

}

import java.util.Scanner;

public class B
{
	static boolean isLeap(int y) { return (y%400 == 0) || (y%4==0 && y%100 != 0); }
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int y = in.nextInt();
		int diff = 0;
		for (int z = y+1 ;; ++z)
		{
			diff = (diff + 365 + (isLeap(z-1)?1:0)) % 7;
			if (diff != 0 || isLeap(z) != isLeap(y)) continue;
			System.out.println(z);
			break;
		}
	}
}

import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class Ed_2016_R13_B
{
	FastReader in;
	PrintWriter out;

	public static void main(String[] args)  {
		new Ed_2016_R13_B().run();
	}

	void run()
	{
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	void solve()
	{
		int y = in.nextInt(), y2 = y;
		int offset = 0;

		while (y2 < 101_000)
		{
			y2++;
			offset++;
			if (isLeapYear(y2)) offset++;
			if (offset % 7 == 0 && isLeapYear(y2) == isLeapYear(y))
				break;
		}
		out.println(y2);
	}

	boolean isLeapYear(int y)
	{
		if (y % 400 == 0) return true;
		if (y % 100 == 0) return false;
		if (y % 4 == 0) return true;
		return false;
	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	    private String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens())
	            try {
	            	tokenizer = new StringTokenizer(br.readLine());
	            }
	            catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        return tokenizer.nextToken();
	    }
		public String nextLine() {
			try	{
				return br.readLine();
			}
			catch(Exception e) {
				throw(new RuntimeException());
			}
		}

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}

import java.io.*;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class TheSameCalendar {
    public static class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int y = fs.nextInt();

        Pairy2[] years = new Pairy2[200001];
        for (int i = 0; i < years.length; ++i) {
            years[i] = new Pairy2();
            if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
                years[i].isLeap = 366;
            }
            else {
                years[i].isLeap = 365;
            }
        }

        years[1000].day = 2;
        int days = 2;
        for (int i = 1000; i < 200000; ++i) {
            days += years[i].isLeap;
            years[i + 1].day = (days) % 7;
        }

        for (int l = y + 1; ; ++l) {
            if (years[l].isLeap == years[y].isLeap && years[l].day == years[y].day) {
                System.out.println(l);
                return;
            }
        }
    }

    private static class Pairy2 {
        int isLeap;
        int day;
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static final int mod = 7;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N;
            N = in.nextInt();
            int M = N + 1;
            int res = 0;
            while (true) {
                if (isLeap(M)) {
                    res += 366;
                    res %= mod;
                } else {
                    res += 365;
                    res %= mod;
                }
                if (isLeap(N) == isLeap(M) && res == 0) {
                    out.println(M);
                    break;
                }
                ++M;
            }
        }

        private boolean isLeap(int x) {
            return (x % 400 == 0 || (x % 4 == 0 && x % 100 != 0));
        }

    }
}

import java.awt.color.*;
import java.util.*;
import java.awt.Point;
import java.math.*;
import java.io.*;
@SuppressWarnings("unused")
public class implementation {int[] b;	String g="";int c=0;int M=1000000000+7;ArrayList<Integer> list=new ArrayList<Integer>();String s;int[] size;int[] id;
int[]ab;int[] data;int mod=100000;LinkedList<Integer> queue=new LinkedList<Integer>();int dis=0;int max=0;ArrayList<Integer>[] arr;
	public static void main(String[] args)  {
                new implementation().solve();
                                  }
	long[] fact;long[] inv;
            public void solve(){
            	int y=sc.nextInt();int c=0;
            	if(y%400==0) {
            		System.out.println(y+28);

            	}
            	else if(y%4==0&&y%100!=0) {

            		  c=0;int g=0;
            		for(int i=y+1;i<=y+10000;i++) {
            			if((i%100!=0&&i%4==0)||i%400==0) {
            				c+=2;
            			}
            			else
            				c++;
            			if(c%7==0&&(((i)%4==0&&(i)%100!=0)||((i)%400==0))) {g=i;
            				break;}
            		}
            		System.out.println(g);

            		}
            	else {c=0;int yy=0;
            		for(int i=y+1;i<=y+1000;i++) {

            			if((i%4==0&&i%100!=0)||i%400==0) {
            				c+=2;
            			}
            			else c++;
            			if(c%7==0&&!(i%400==0||(i%4==0&&i%100!=0))) {
            				yy=i;
            				break;}
            		}
            		System.out.println(yy);

            	}

            }

            public class Node{
       	     int x;int color;int y;
       	       Node par;
       	        public Node(int a,int b) {
       	          	x=a;color=b;

       	             }
                         }
                     class sortbyweight implements Comparator<Node>{

       				@Override
       				public int compare(Node a, Node b) {
       					// TODO Auto-generated method stub

       					if(a.color<b.color)
                			return 1;
                		else
                			return -1;
       				}}

       				 FastReader sc=new FastReader();
       				 static class FastReader
       				     {
       				         BufferedReader br;
       				         StringTokenizer st;

       				         public FastReader()
       				         {
       				             br = new BufferedReader(new
       				                      InputStreamReader(System.in));
       				         }

       				         String next()
       				         {
       				             while (st == null || !st.hasMoreElements())
       				             {
       				                 try
       				                 {
       				                     st = new StringTokenizer(br.readLine());
       				                 }
       				                 catch (IOException  e)
       				                 {
       				                     e.printStackTrace();
       				                 }
       				             }
       				             return st.nextToken();
       				         }

       				         int nextInt()
       				         {
       				             return Integer.parseInt(next());
       				         }

       				         long nextLong()
       				         {
       				             return Long.parseLong(next());
       				         }

       				         double nextDouble()
       				         {
       				             return Double.parseDouble(next());
       				         }

       				         String nextLine()
       				         {
       				             String str = "";
       				             try
       				             {
       				                 str = br.readLine();
       				             }
       				             catch (IOException e)
       				             {
       				                 e.printStackTrace();
       				             }
       				             return str;
       				         }
       				     }}

//package main;

import java.io.*;
import java.util.*;
import java.math.*;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    long mod = 998244353;
    StringBuilder res = new StringBuilder(1000005);
    void run() throws Exception {
        int year = ni(), Y = year;

        int day = 0;
        while(true) {
            day++;
            if(isLeapYear(year)) {
                day++;
            }
            year++;
            day %= 7;
            if(day == 0 && isLeapYear(Y) == isLeapYear(year)) {
                System.out.println(year);
                return;
            }
        }
    }

    boolean isLeapYear(int year) {
        return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
    }

    //Reader & Writer
    String nt() throws Exception {
        if (stk == null || !stk.hasMoreTokens())
            stk = new StringTokenizer(br.readLine(), " ");
        return stk.nextToken();
    }

    char[] nc() throws Exception {
        return nt().toCharArray();
    }

    int ni() throws Exception {
        return Integer.parseInt(nt());
    }

    long nl() throws Exception {
        return Long.parseLong(nt());
    }

    double nd() throws Exception {
        return Double.parseDouble(nt());
    }

    //Some Misc methods
    long get(int l, int r, long[] a) {
        return l == 0 ? a[r] : a[r] - a[l - 1];
    }

    void shuffle(long[] a) {
        Random r = new Random();
        for(int i = 0; i < a.length; i++) {
            int idx = r.nextInt(a.length);
            long temp = a[i];
            a[i] = a[idx];
            a[idx] = temp;
        }
    }

    void reverse(long[] a) {
        for(int i = 0, j = a.length - 1; i < j; i++, j--) {
            long temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
    }

    void print(int[] a) {
        System.out.println(Arrays.toString(a));
    }
}

import java.util.Scanner;
public class Program {
	public boolean isLeapYear(int year){
	boolean leapyear = false;
	if(year%4 == 0){
	leapyear = true;
	}
	if (year %100 == 0){
	leapyear = false;
	}
	if (year %400 == 0){
	leapyear = true;
	}
	return leapyear;
	}

	public static void main(String[] args) {
	Program isLeapYear = new Program();
	Scanner input = new Scanner(System.in);
	int year = input.nextInt();
	boolean y = isLeapYear.isLeapYear(year);
	int counter = 0;
	if(y == true){
	counter = 1;
	}
	for(int i = 0 ; i < Integer.MAX_VALUE; i++){
	year ++;
	boolean yy = isLeapYear.isLeapYear(year);
	counter ++ ;
	if(y == yy){
	if(counter%7 ==0){
	System.out.println(year);
	break;
	}
	}
	if(yy == true){
	counter++;
	}
	}
	input.close();
	}

	}

/*-
 * Codeforces problem :
 * http://codeforces.com/problemset/problem/678/B
 *
 * Print the only integer y' — the next year after
 * y when the calendar will be the same. Note that
 * you should find the first year after y with the
 * same calendar.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Karthik Venkataraman
 * @email kafy83@gmail.com
 */
public class SameCalendar {

    private InputReader sc = new InputReader(System.in);
    private PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    private boolean isLeap(int y) {
        return y % 400 == 0 || (y % 4 == 0 && y % 100 > 0);
    }

    private void compute() {
        int n = sc.nextInt(), d = 0;
        boolean leap = isLeap(n);
        for (;;) {
            d = isLeap(n++) ? (d + 2) % 7 : (d + 1) % 7;
            if (d == 0 && isLeap(n) == leap) {
                break;
            }
        }
        pw.print(n);
        pw.flush();
    }

    class InputReader {

        private static final int INPUT_KB = 1024;
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), INPUT_KB);
        }

        String readNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    throw new IllegalStateException(ex);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(readNext());
        }
    }

    public static void main(String... args) {
        SameCalendar sca = new SameCalendar();
        sca.compute();
    }
}

import java.io.*;
import java.util.StringTokenizer;

/**
 * Created by Alvin on 8/14/2016.
 */

public class Codeforces_Educational_round_13_TheSameCalendar {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int n = input.nextInt();
        boolean leapYear = isLeap(n);
        int day = 0;
        do {
            day++;
            if (isLeap(n)) {
                day++;
            }
            n++;
            day %= 7;
        } while(day > 0 || isLeap(n) != leapYear);
        out.println(n);

    }

    public static boolean isLeap(int y) {
        return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

        public FScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}

import java.io.*;
import java.util.*;
import java.math.*;

public class TheSameCalendar{
	public static MyScanner sc = new MyScanner();
	public static PrintWriter out;

	static boolean isLeap(int year)
	{
		if(year % 400 == 0)
			return true;
		if(year % 4 == 0 && year % 100 != 0)
			return true;

		return false;
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		// <!--inicio solucion-->

		int YEAR_ORI = sc.nextInt();
		int DAY_OF_WEEK_ORI = 0;

		int year_act = YEAR_ORI;
		int day_of_week_act = DAY_OF_WEEK_ORI;

		for(int i=0; ;i++)
		{
			if(isLeap(year_act))
				day_of_week_act = (day_of_week_act+2)%7;
			else
				day_of_week_act = (day_of_week_act+1)%7;

			year_act++;

			if(isLeap(year_act) == isLeap(YEAR_ORI) && day_of_week_act == DAY_OF_WEEK_ORI)
			{
				out.println(YEAR_ORI + i + 1);
				break;
			}
		}

		// </!--fin solucion-->
		out.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		BigInteger nextBigInteger() {
			return new BigInteger(next());
		}
		BigInteger nextBigInteger(int radix) {
			return new BigInteger(next(), radix);
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
		public boolean hasNext() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String line = br.readLine();
					if (line == null) {
						return false;
					}
					st = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return true;
		}
	}
}

/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

public class codeforces {
	public static void main (String[] args)
	{
		Scanner in = new Scanner(System.in);

	    int y = in.nextInt();
	    long count,i=0,ans=0;

	    boolean year = isLeapyear(y),flage;

	    if(year)
	        i = 2;
	    else
	        i = 1;

	    count = i;

	    while(true)
	    {
	        y += 1;
	        flage = isLeapyear(y);

	        if(flage)
	            count += 2;
	        else
	            count += 1;

	        ans = count%7;

	        if(ans==i && flage==year)
	            break;
	    }

	    System.out.println(y);
	}

	public static boolean isLeapyear(int y)
	{
	   if(y%400==0 || (y%4==0 && y%100!=0))
	       return true;

	   return false;
	}
}

import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        long y = nl();
        boolean leap = leap(y);
        long d = 0;
        do{
            if(leap(y))d+=2;
            else d++;
            y++;d%=7;
        }while(d != 0 || leap != leap(y));
        pn(y);
    }
    boolean leap(long x){
        return x%400 == 0 || (x%4 == 0 && x%100 != 0);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    long IINF = (long)1e18, mod = 1000000007;
    final int INF = (int)1e9, MX = (int)2e5+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;
    static boolean multipleTC = false, memory = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int y=Integer.parseInt(st.nextToken());
	//System.out.println(isLeap(2004));
		int cnt=0;
		for(int i=y;i<=100999;){
			i++;
			if((i!=y)&&(isLeap(i-1)||isSpLeap(i-1))){
				cnt=cnt+2;
			}
			else{
				cnt=cnt+1;
			}

		//	System.out.println(i+" "+cnt);
			if((cnt)%7==0){

				if(isLeap(y)||isSpLeap(y)){
					if(isLeap(i)||isSpLeap(i)){
						System.out.println(i);
						break;
					}
					continue;
				}
				else{
					if(!(isLeap(i)||isSpLeap(i))){
							System.out.println(i);
							break;
					}
					continue;
				}
			}
		}

	}
	public static boolean isLeap(int y){
		if((y%4==0)&&((y%100)!=0))
			return true;
		return false;
	}
	public static boolean isSpLeap(int y){
		if(y%400==0)
			return true;
		return false;
	}
}

import java.util.*;
import java.io.*;

public class TestClass{

	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String args[]) throws Exception
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int y = Integer.parseInt(in.readLine());
		int c=0,cnt=0,f=0,g=0;
		if((y%4==0  && y%100!=0) || y%400==0)
		{
			f=1;
		}
		for(int i=y+1;;i++)
		{
			g = 0;
			/*if(i == 100010)
			{
				System.out.println(i+" "+c+" "+f+" ");
			}*/
			if((i%4==0  && i%100!=0) || i%400==0)
			{
				c=(c+2)%7;
				cnt++;
				//System.out.println("here"+i+" "+c+" "+cnt);
			}
			else
			{
				c=(c+1)%7;
				cnt++;
				//System.out.println(i+" "+c+" "+cnt);
			}

			if(c==0)
			{
				/*if(i == 100010)
				{
					System.out.println(i+" "+c+" "+f+" ");
				}*/
				if((i%4==0  && i%100!=0) || i%400==0)
				{
					g=1;
				}
				if(f==1 && g==1)
				{
					out.println(cnt+y);
					break;
				}
				else if(f==0 && g==0)
				{
					out.println(cnt+y);
					break;
				}
			}
		}
		out.close();
	}

}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;

public class B {
	public static void main(String[] args) throws IOException {
		File inputFile = new File("entradaB");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null) {
			int year = Integer.parseInt(line);
			GregorianCalendar c = new GregorianCalendar();
			c.set(year, 0, 1);
			int dayini = c.get(Calendar.DAY_OF_WEEK), dayfin;
			boolean bicini = (year % 400L == 0L) || (year % 4L == 0L && year % 100L != 0L), bicifin;
			do {
				c.add(Calendar.YEAR, 1);
				dayfin = c.get(Calendar.DAY_OF_WEEK);
				year++;
				bicifin = (year % 400L == 0L) || (year % 4L == 0L && year % 100L != 0L);
			} while (dayini != dayfin || bicini != bicifin);
			out.append(year + "\n");
		}
		System.out.print(out);
	}

	static int[] readInts(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		int a[] = new int[st.countTokens()], index = 0;
		while (st.hasMoreTokens())
			a[index++] = Integer.parseInt(st.nextToken());
		return a;
	}

	static long[] readLongs(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		long a[] = new long[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Long.parseLong(st.nextToken());
		return a;
	}

	static double[] readDoubles(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		double a[] = new double[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Double.parseDouble(st.nextToken());
		return a;
	}
}

//package proje;

import java.util.*;

public class limbo
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int year = s.nextInt();

		int sum=0;

		if(year%4==0 && year%100!=0)
		{
			year+=28;
			System.out.println(year);
		}
		else
		{
			while(true)
			{
				if(year%4==0 && year%100!=0 )
					sum+=366;
				else
					sum+=365;
				++year;
				if(sum%7==0)
				{
				System.out.println(	year);
				break;
				}

			}
		}
	}
}

//package com.codeforces.competitions.educational.year2016.apriltojune.round13;

import java.io.*;
import java.util.*;

public final class TaskB
{
    public static void main(String[] args)
    {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);

		Solver solver = new Solver(in, out);
		solver.solve(1);

        out.flush();

        in.close();
        out.close();
    }

    static class Solver
    {
        int n, arr[];
        InputReader in;
        OutputWriter out;

        public Solver(InputReader in, OutputWriter out)
        {
        	this.in = in;
        	this.out = out;
        }

		void solve(int testNumber)
		{
			n = in.nextInt();

/*			System.out.println("isLeap(n) : " + isLeap(n));
			System.out.println(" " + (50496 % 400) + ", : " + (50496 % 4) + ", : " + (50496 % 100));
			System.out.println(" " + (50500 % 400) + ", : " + (50500 % 4) + ", : " + (50500 % 100));*/

			if (isLeap(n))
				out.println(n + 28);
			else if (isLeap(n - 1) || isLeap(n - 2))
				out.println(n + 6);
			else if (isLeap(n + 1) && !isLeap(n - 3))
				out.println(n + 11);
			else if (isLeap(n + 2) && !isLeap(n - 2))
				out.println(n + 11);
			else if (isLeap(n + 3) && !isLeap(n - 1))
				out.println(n + 6);
			else if (isLeap(n - 4) && isLeap(n + 4) && !isLeap(n))
				out.println(n + 6);
			else if (!isLeap(n + 1) && isLeap(n - 3))
				out.println(n + 6);
			else if (isLeap(n - 2) && !isLeap(n + 2))
				out.println(n + 12);
			else if (isLeap(n - 1) && !isLeap(n + 3))
				out.println(n + 11);
			else
				out.println(n + 11);
		}

		boolean isLeap(int year)
		{
			if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
				return true;

			return false;
		}

	}

    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt()
        {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c & 15;

                c = read();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public int[] nextIntArray(int arraySize)
        {
            int array[] = new int[arraySize];

            for (int i = 0; i < arraySize; i++)
                array[i] = nextInt();

            return array;
        }

        public long nextLong()
        {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sign = 1;

            if (c == '-')
            {
                sign = -1;

                c = read();
            }

            long result = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                result *= 10;
                result += c & 15;

                c = read();
            } while (!isSpaceChar(c));

            return result * sign;
        }

        public long[] nextLongArray(int arraySize)
        {
            long array[] = new long[arraySize];

            for (int i = 0; i < arraySize; i++)
                array[i] = nextLong();

            return array;
        }

        public float nextFloat() // problematic
        {
            float result, div;
            byte c;

            result = 0;
            div = 1;
            c = (byte) read();

            while (c <= ' ')
                c = (byte) read();

            boolean isNegative = (c == '-');

            if (isNegative)
                c = (byte) read();

            do
            {
                result = result * 10 + c - '0';
            } while ((c = (byte) read()) >= '0' && c <= '9');

            if (c == '.')
                while ((c = (byte) read()) >= '0' && c <= '9')
                    result += (c - '0') / (div *= 10);

            if (isNegative)
                return -result;

            return result;
        }

        public double nextDouble() // not completely accurate
        {
            double ret = 0, div = 1;
            byte c = (byte) read();

            while (c <= ' ')
                c = (byte) read();

            boolean neg = (c == '-');

            if (neg)
                c = (byte) read();

            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = (byte) read()) >= '0' && c <= '9');

            if (c == '.')
                while ((c = (byte) read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);

            if (neg)
                return -ret;

            return ret;
        }

        public String next()
        {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            StringBuilder res = new StringBuilder();

            do
            {
                res.appendCodePoint(c);

                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String nextLine()
        {
            int c = read();

            StringBuilder result = new StringBuilder();

            do
            {
                result.appendCodePoint(c);

                c = read();
            } while (!isNewLine(c));

            return result.toString();
        }

        public boolean isNewLine(int c)
        {
            return c == '\n';
        }

        public void close()
        {
            try
            {
                stream.close();
            } catch (IOException e)
            {
                e.printStackTrace();
            }
        }

    }

    static class OutputWriter
    {
        private PrintWriter writer;

        public OutputWriter(OutputStream stream)
        {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                    stream)));
        }

        public OutputWriter(Writer writer)
        {
            this.writer = new PrintWriter(writer);
        }

        public void println(int x)
        {
            writer.println(x);
        }

        public void print(int x)
        {
            writer.print(x);
        }

        public void println(int array[], int size)
        {
            for (int i = 0; i < size; i++)
                println(array[i]);
        }

        public void print(int array[], int size)
        {
            for (int i = 0; i < size; i++)
                print(array[i] + " ");
        }

        public void println(long x)
        {
            writer.println(x);
        }

        public void print(long x)
        {
            writer.print(x);
        }

        public void println(long array[], int size)
        {
            for (int i = 0; i < size; i++)
                println(array[i]);
        }

        public void print(long array[], int size)
        {
            for (int i = 0; i < size; i++)
                print(array[i]);
        }

        public void println(float num)
        {
            writer.println(num);
        }

        public void print(float num)
        {
            writer.print(num);
        }

        public void println(double num)
        {
            writer.println(num);
        }

        public void print(double num)
        {
            writer.print(num);
        }

        public void println(String s)
        {
            writer.println(s);
        }

        public void print(String s)
        {
            writer.print(s);
        }

        public void println()
        {
            writer.println();
        }

        public void printSpace()
        {
            writer.print(" ");
        }

        public void flush()
        {
            writer.flush();
        }

        public void close()
        {
            writer.close();
        }

    }

	static class CMath
	{
		static long power(long number, long power)
		{
			if (number == 1 || number == 0 || power == 0)
				return 1;

			if (power == 1)
				return number;

			if (power % 2 == 0)
				return power(number * number, power / 2);
			else
				return power(number * number, power / 2) * number;
		}

		static long modPower(long number, long power, long mod)
		{
			if (number == 1 || number == 0 || power == 0)
				return 1;

			number = mod(number, mod);

			if (power == 1)
				return number;

			long square = mod(number * number, mod);

			if (power % 2 == 0)
				return modPower(square, power / 2, mod);
			else
				return mod(modPower(square, power / 2, mod) * number, mod);
		}

		static long moduloInverse(long number, long mod)
		{
			return modPower(number, mod - 2, mod);
		}

		static long mod(long number, long mod)
		{
			return number - (number / mod) * mod;
		}

		static int gcd(int a, int b)
		{
			if (b == 0)
				return a;
			else
				return gcd(b, a % b);
		}

	}

}

import java.util.Scanner;

public class sameCalender {
	public static boolean isLeap(int y){
		boolean leap = false;
		if(y%4!=0)
			leap = false;
		else
			if(y%100!=0)
				leap = true;
			else
				if(y%400!=0)
					leap=false;
				else
					leap = true;
		return leap;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int y = sc.nextInt();
		boolean leap = isLeap(y);
//		System.out.println(leap);
		if(leap){
			System.out.println(y+28);
		}
		else
		{
			int nxt = y+1;
			int count = 0;
			while(true){
				leap = isLeap(nxt);
				if(leap){
					count+=2;
				}
				else
					count++;
				if(count==7){
					System.out.println(nxt);
					break;
				}
				nxt++;
			}
		}
	}
}

/**
 * @(#)SameCal.java
 *
 *
 * @author Suyash Bhalla
 * @version 1.00 2016/6/13
 */
import java.io.*;
import java.util.*;

public class SameCal{

    public static void main(String args[])throws IOException{

    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    	int N=Integer.parseInt(br.readLine());
    	boolean isLeap=false;

    	while(true){
    		isLeap=false;
    		if(checkYear(N)==2){
    			isLeap=true;
    			N+=28;
    		}else{
    			N+=6;
    		}
    		if((isLeap&&checkYear(N)==2)||(!isLeap&&checkYear(N)==1)){
    			break;
    		}

    	}

    	System.out.println(N);

    }

    public static int checkYear(int N){
    	if((N%100==0&&N%400==0)||(N%100!=0&&N%4==0)){
    		return 2;
    	}else{
    		return 1;
    	}
    }

}

import java.io.*;
import java.util.*;
import java.math.*;

public class TheSameCalendar{
	public static MyScanner sc = new MyScanner();
	public static PrintWriter out;

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		// <!--inicio solucion-->

		int YEAR = sc.nextInt();

		GregorianCalendar calendario = new GregorianCalendar();
		calendario.setGregorianChange(new Date(Long.MIN_VALUE));

		calendario.setTime(new Date(YEAR-1900, 0, 1));
		int firstOfJanuary = calendario.getTime().getDay();
		calendario.setTime(new Date(YEAR-1900, 2, 1));
		int firstOfMarch = calendario.getTime().getDay();

		//out.println(firstOfMarch);

		//out.println("" + calendario.getTime());

		for(int i=1; ;i++)
		{
			calendario.setTime(new Date(YEAR-1900+i, 0, 1));
			int newFirstOfJanuary = calendario.getTime().getDay();
			calendario.setTime(new Date(YEAR-1900+i, 2, 1));
			int newFirstOfMarch = calendario.getTime().getDay();

			//out.println(newFirstOfMarch);

			//out.println("" + calendario.getTime());

			if(firstOfJanuary == newFirstOfJanuary && firstOfMarch == newFirstOfMarch)
			{
				out.println(YEAR+i);
				break;
			}
		}

		// </!--fin solucion-->
		out.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		BigInteger nextBigInteger() {
			return new BigInteger(next());
		}
		BigInteger nextBigInteger(int radix) {
			return new BigInteger(next(), radix);
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
		public boolean hasNext() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String line = br.readLine();
					if (line == null) {
						return false;
					}
					st = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return true;
		}
	}
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author evgen
 */
public class class1 {
    public static void main(String args[])
{InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int god=in.nextInt();
        boolean cod=false;
        int y=0;
        if(!((god%4==0&&god%100!=0)||god%400==0)){
        while(!cod)
        {
        if((god%4==0&&god%100!=0)||god%400==0){y+=366;}
        else{y+=365;}
        if(y%7==0){cod=true;}
        god++;
        }   }
        if((god%4==0&&god%100!=0)||god%400==0)
        {
         while(!cod)
        {
        if((god%4==0&&god%100!=0)||god%400==0){y+=366;out.println(1);}
        else{y+=365;out.println(2);}

        god++;
        if(y%7==0&&(god%4==0&&god%100!=0)||god%400==0){cod=true;}
        }
        }
out.print(god);
        out.close();}
static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
}}

					import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
									public class Solution1 implements Runnable
									{
										static final long MAX = 1000000007L;
										static class InputReader
										{
											private InputStream stream;
											private byte[] buf = new byte[1024];
											private int curChar;
											private int numChars;
											private SpaceCharFilter filter;
											private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

											public InputReader(InputStream stream)
											{
												this.stream = stream;
											}

											public int read()
											{
												if (numChars==-1)
													throw new InputMismatchException();

												if (curChar >= numChars)
												{
													curChar = 0;
													try
													{
														numChars = stream.read(buf);
													}
													catch (IOException e)
													{
														throw new InputMismatchException();
													}

													if(numChars <= 0)
														return -1;
												}
												return buf[curChar++];
											}

											public String nextLine()
											{
												String str = "";
									            try
									            {
									                str = br.readLine();
									            }
									            catch (IOException e)
									            {
									                e.printStackTrace();
									            }
									            return str;
											}
											public int nextInt()
											{
												int c = read();

												while(isSpaceChar(c))
													c = read();

												int sgn = 1;

												if (c == '-')
												{
													sgn = -1;
													c = read();
												}

												int res = 0;
												do
												{
													if(c<'0'||c>'9')
														throw new InputMismatchException();
													res *= 10;
													res += c - '0';
													c = read();
												}
												while (!isSpaceChar(c));

												return res * sgn;
											}

											public long nextLong()
											{
												int c = read();
												while (isSpaceChar(c))
													c = read();
												int sgn = 1;
												if (c == '-')
												{
													sgn = -1;
													c = read();
												}
												long res = 0;

												do
												{
													if (c < '0' || c > '9')
														throw new InputMismatchException();
													res *= 10;
													res += c - '0';
													c = read();
												}
												while (!isSpaceChar(c));
													return res * sgn;
											}

											public double nextDouble()
											{
												int c = read();
												while (isSpaceChar(c))
													c = read();
												int sgn = 1;
												if (c == '-')
												{
													sgn = -1;
													c = read();
												}
												double res = 0;
												while (!isSpaceChar(c) && c != '.')
												{
													if (c == 'e' || c == 'E')
														return res * Math.pow(10, nextInt());
													if (c < '0' || c > '9')
														throw new InputMismatchException();
													res *= 10;
													res += c - '0';
													c = read();
												}
												if (c == '.')
												{
													c = read();
													double m = 1;
													while (!isSpaceChar(c))
													{
														if (c == 'e' || c == 'E')
															return res * Math.pow(10, nextInt());
														if (c < '0' || c > '9')
															throw new InputMismatchException();
														m /= 10;
														res += (c - '0') * m;
														c = read();
													}
												}
												return res * sgn;
											}

											public String readString()
											{
												int c = read();
												while (isSpaceChar(c))
													c = read();
												StringBuilder res = new StringBuilder();
												do
												{
													res.appendCodePoint(c);
													c = read();
												}
												while (!isSpaceChar(c));

												return res.toString();
											}

											public boolean isSpaceChar(int c)
											{
												if (filter != null)
													return filter.isSpaceChar(c);
												return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
											}

											public String next()
											{
												return readString();
											}

											public interface SpaceCharFilter
											{
												public boolean isSpaceChar(int ch);
											}
										}

										public static void main(String args[]) throws Exception
										{
											new Thread(null, new Solution1(),"Solution1",1<<26).start();
										}
										long gcd(long a, long b)
									    {
									        if (a == 0)
									            return b;

									        return gcd(b%a, a);
									    }
									    // method to return LCM of two numbers
										 long lcm(long a, long b)
										    {
										        return (a*b)/gcd(a, b);
										    }
										final long bit = 60;
										public void run()
										{
											InputReader sc= new InputReader(System.in);
											PrintWriter w= new PrintWriter(System.out);
											int year = sc.nextInt();
											if((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)){
												w.println(year + 28);
											}else{
												w.println(year + 6);
											}
											w.close();
										}

										static class Pair implements Comparable<Pair>{
											int a;
											long b;

											Pair(){}
											Pair(int a,long b){
												this.a = a;
												this.b = b;

											}
											public int compareTo(Pair p){
												return Integer.compare(this.a,p.a);
											}
										}
						}

import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class Ed_2016_R13_B
{
	FastReader in;
	PrintWriter out;

	public static void main(String[] args)  {
		new Ed_2016_R13_B().run();
	}

	void run()
	{
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	void solve()
	{
		int y = in.nextInt(), y2 = y;
		int offset = 0;

		while (y2 < 100_000)
		{
			y2++;
			offset++;
			if (isLeapYear(y2)) offset++;
			if (offset % 7 == 0 && isLeapYear(y2) == isLeapYear(y))
				break;
		}
		out.println(y2);
	}

	boolean isLeapYear(int y)
	{
		if (y % 400 == 0) return true;
		if (y % 100 == 0) return false;
		if (y % 4 == 0) return true;
		return false;
	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	    private String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens())
	            try {
	            	tokenizer = new StringTokenizer(br.readLine());
	            }
	            catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        return tokenizer.nextToken();
	    }
		public String nextLine() {
			try	{
				return br.readLine();
			}
			catch(Exception e) {
				throw(new RuntimeException());
			}
		}

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}

import java.awt.color.*;
import java.util.*;
import java.awt.Point;
import java.math.*;
import java.io.*;
@SuppressWarnings("unused")
public class implementation {int[] b;	String g="";int c=0;int M=1000000000+7;ArrayList<Integer> list=new ArrayList<Integer>();String s;int[] size;int[] id;
int[]ab;int[] data;int mod=100000;LinkedList<Integer> queue=new LinkedList<Integer>();int dis=0;int max=0;ArrayList<Integer>[] arr;
	public static void main(String[] args)  {
                new implementation().solve();
                                  }
	long[] fact;long[] inv;
            public void solve(){
            	int y=sc.nextInt();
            	if(y%4==0||y%400==0) {
            		System.out.println(y+28);

            	}
            	else {
            		System.out.println(y+6);
            	}

            }

            public class Node{
       	     int x;int color;int y;
       	       Node par;
       	        public Node(int a,int b) {
       	          	x=a;color=b;

       	             }
                         }
                     class sortbyweight implements Comparator<Node>{

       				@Override
       				public int compare(Node a, Node b) {
       					// TODO Auto-generated method stub

       					if(a.color<b.color)
                			return 1;
                		else
                			return -1;
       				}}

       				 FastReader sc=new FastReader();
       				 static class FastReader
       				     {
       				         BufferedReader br;
       				         StringTokenizer st;

       				         public FastReader()
       				         {
       				             br = new BufferedReader(new
       				                      InputStreamReader(System.in));
       				         }

       				         String next()
       				         {
       				             while (st == null || !st.hasMoreElements())
       				             {
       				                 try
       				                 {
       				                     st = new StringTokenizer(br.readLine());
       				                 }
       				                 catch (IOException  e)
       				                 {
       				                     e.printStackTrace();
       				                 }
       				             }
       				             return st.nextToken();
       				         }

       				         int nextInt()
       				         {
       				             return Integer.parseInt(next());
       				         }

       				         long nextLong()
       				         {
       				             return Long.parseLong(next());
       				         }

       				         double nextDouble()
       				         {
       				             return Double.parseDouble(next());
       				         }

       				         String nextLine()
       				         {
       				             String str = "";
       				             try
       				             {
       				                 str = br.readLine();
       				             }
       				             catch (IOException e)
       				             {
       				                 e.printStackTrace();
       				             }
       				             return str;
       				         }
       				     }}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    //---------------------------------------------------------------------------

    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        //-----------------------------------------------------------------------
        int n = in.nextInt();
        int ans = n;
        if (n % 4 != 0) {
            ans = n + 6;
        } else if (n % 100 != 0) {
            ans = n + 28;
        } else if (n % 400 != 0) {
            ans = n + 6;
        } else {
            ans = n + 28;
        }
        out.println(ans);
        //-----------------------------------------------------------------------
        out.close();
    }
    //---------------------------------------------------------------------------

    static class Pair implements Comparator {

        int first, second;

        public Pair() {

        }

        public Pair(int f, int s) {
            this.first = f;
            this.second = s;
        }

        @Override
        public int compare(Object o1, Object o2) {
            Pair p1 = (Pair) o1;
            Pair p2 = (Pair) o2;
            int ret = -Integer.compare(p1.first, p2.first);
            if (ret == 0) {
                ret = -Integer.compare(p1.second, p2.second);
            }
            return ret;
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char[] nextCharArray() {
            return next().toCharArray();
        }

        public boolean hasNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String s = reader.readLine();
                    if (s == null) {
                        return false;
                    }
                    tokenizer = new StringTokenizer(s);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }

        public void skipLine() {
            try {
                tokenizer = null;
                reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

import java.util.Scanner;

public class Main {
  static int y;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    y = sc.nextInt();

    int yy = y + 1, count = 1;
    if(!isLeapYear(y)){
      while((count % 7) != 0){
        if(isLeapYear(yy)){
          ++count;
        }
        ++count;  ++yy;
      }
    }
    else{
      ++count;
      while(!((count % 7) == 0 && isLeapYear(yy))){
        if(isLeapYear(yy)){
          ++count;
        }
        ++count;  ++yy;
      }
    }

    System.out.println(yy);
  }

  private static boolean isLeapYear(int year){
    if(year % 4 == 0){
      if(year % 100 == 0){
        if(year % 400 == 0){
          return true;
        }
        else{
          return false;
        }
      }
      else{
        return true;
      }
    }
    else{
      return false;
    }
  }
}

import java.io.*;
import java.util.StringTokenizer;

/**
 * Created by Alvin on 7/5/2016.
 */

public class Codeforces_Educational_round_13_TheSameCalendar {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int n = input.nextInt();
        out.println((n % 400 == 0 || n % 4 == 0) && n % 100 != 0 ? n + 28 : n + 6);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

        public FScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}

/**
 * @(#)SameCal.java
 *
 *
 * @author Suyash Bhalla
 * @version 1.00 2016/6/13
 */
import java.io.*;
import java.util.*;

public class SameCal{

    public static void main(String args[])throws IOException{

    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    	int N=Integer.parseInt(br.readLine());

    	boolean L=checkYear(N)==2?true:false;
    	int cnt=0;
    	if(L){

    		while(true){
    			cnt+=checkYear(N++);
    			if(cnt%7==0&&checkYear(N)==2){
    				break;
    			}
    		}

    	}else{
    		while(true){
    			cnt+=checkYear(N++);
    			if(cnt%7==0){
    				break;
    			}

    		}
    	}

    	System.out.println(N);
    }

    public static int checkYear(int N){
    	if((N%100==0&&N%400==0)||(N%100!=0&&N%4==0)){
    		return 2;
    	}else{
    		return 1;
    	}
    }

}

import java.util.*;

public class ProblemB {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		int r = n%4;
		if(r == 0)
			ans = n + 28;
		else if(r == 1 || r == 2)
			ans = n + 6;
		else if(r == 3)
			ans = n + 11;
		System.out.println(ans);
	}
}

import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static int n=0;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		if(leap(n)){
			System.out.println(n+28);
		}
		else{
			int temp = n+6;
			while(leap(temp)){
				temp = temp+6;
			}
			System.out.println(temp);
		}

	}

	public static boolean leap(int a){
		if(a%400==0 || (a%4==0 && a%100!=0)){
			return true;
		}
		else{
			return false;
		}
	}

}

import java.util.Scanner;

public class SameCalendar {
    static boolean isLeap(long year) {
        if ( (year % 400 == 0) || ( year % 4 == 0 && year % 100 != 0) ) return true;
        return false;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long year = scanner.nextLong();
        if (isLeap(year)) {
            System.out.println((year+28));
            return;
        }
        int leapCount = 0;
        for (long y = year+1; y <year+6;y++) {
            if (isLeap(y)) leapCount++;
        }
        if (leapCount == 1) {
            year +=6;
        }
        else year+= 10;
        System.out.println(year);
        scanner.close();
    }
}

import java.util.*;
public class main {
    public static void main(String args[]) throws Exception {
        Scanner in = new Scanner(System.in);
        int n =in.nextInt();
        int k=1;
        int i=0;
        while (i==0){

            n++;
            if (k%4==0 || (k%400==0 && k%100!=0)){
                k+=2;
            }
            else k++;
            if(k%7==0)i++;
        }
        System.out.println(n+1);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author JENISH
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTheSameCalendar solver = new BTheSameCalendar();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTheSameCalendar {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {

            long y = in.scanLong();
            if (y % 4 == 0) {
                out.println(y + 28);
            } else if (y % 4 == 1) {
                out.println(y + 6);
            } else {
                out.println(y + 11);

            }

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

    }
}

import java.util.Scanner;
public class Calendar{
	static Scanner sc = new Scanner(System.in);
	static boolean isleap(int y){
		if((y%400==0)||((y%4==0)&&(y%100!=0))){
			return true;
		}else{
			return false;
		}
	}
	public static void main (String[] args){
		int y=sc.nextInt();
		int l=0;
		int i=1;
		if(isleap(y)){
			l=2;
			i+=2;
			y++;
		}else{
			l=1;
			i++;
			y++;
		}
		while(i!=1){
			if (isleap(y)){
				i+=2;
				y++;
			}else{
				i++;
				y++;
			}
			if(i>7){i%=7;}
			if((l==2)&&(i==1)&&(!(isleap(y)))){
				i++;
				y++;
			}
			if(i>7){i%=7;}
		}
		System.out.print(y);
	}
}

/* Author : Kishan Patel
 * From   : DAIICT
 */
import java.io.*;
import java.util.*;

public class Que2 {
	public static void main(String args[]) throws Exception {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		if(checkLeap(n)){
			n=n+28;
		}
		else if(n%10==1) n=n+6;
		else if(n%10==3) n=n+11;
		else if(n%10==2) n=n+11;
		System.out.println(n);
	}

	private static boolean checkLeap(int n) {
		if(n%400==0) return true;
		else if(n%4==0 && n%10!=0){
			return true;
		}
		else return false;

	}
}

import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P678B {

  boolean isLeap(int y) {
    return ((((y % 4) == 0) && (y % 100) != 0) || ((y % 400) == 0));
  }

  public void run() throws Exception {
    int y = nextInt();
    println(y + (isLeap(y) ? 28 : 6));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P678B().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    return ((b > 0) ? gcd(b, a % b) : a);
  }
}

import java.util.*;
public class main {
    public static void main(String args[]) throws Exception {
        Scanner in = new Scanner(System.in);
        int n =in.nextInt();
        int k=0;
        int f = n;
        int g=0;
        int j=0;
        int i=0;
        if ((n%100)%4==0 |n%400==0)g=1;
        while (i==0){

            f++;
            if ((f%100)%4==0 ||f%400==0){
                k+=2;
            }
            else k++;
            if ((f%100)%4==0 || f%400==0)j=1;
            else j=0;
            if(k%7==0 && g==j)i++;
        }
        System.out.println(f);
    }
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    public static void main(String[] args) throws java.lang.Exception {
        Reader pm =new Reader();
        //Scanner pm = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int t = 1;
        while(t-- > 0){
            long n = pm.nextInt();
            int fl = 0;
            int odd = 0;
            if(((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0))
                fl = 1;
            while(true){
                if(((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0)) {
                    odd+=2;
                    n++;
                } else {
                    odd++;
                    n++;
                }
                if(odd % 7 == 0){
                    if(fl ==1){
                        if(((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0)){
                            System.out.println(n);
                            return;
                        }
                        else
                            continue;
                    }
                    System.out.println(n);
                    return;
                }
            }
        }

    }

    static int countInRange(int arr[], int n, int x, int y) {
        // initialize result
        int count = 0;
        count = upperIndex(arr, n, y) -
                lowerIndex(arr, n, x) + 1;
        return count;
    }

    static int lowerIndex(int arr[], int n, int x) {
        int l = 0, h = n - 1;
        while (l <= h)
        {
            int mid = (l + h) / 2;
            if (arr[mid] >= x)
                h = mid - 1;
            else
                l = mid + 1;
        }
        return l;
    }

    // function to find last index <= y
    static int upperIndex(int arr[], int n, int y) {
        int l = 0, h = n - 1;
        while (l <= h)
        {
            int mid = (l + h) / 2;
            if (arr[mid] <= y)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }

    public static StringBuilder dec_to_bin(long n) {
        // decimal to binary upto 30 binaries
        if(n==0) {
            StringBuilder str=new StringBuilder("");
            for(int i=0;i<30;i++) {
                str.append("0");
            }
            return str;
        }
        StringBuilder str=new StringBuilder("");
        while(n!=0) {
            str.append(n%2L);
            n/=2L;
        }
        str=str.reverse();
        StringBuilder tmp_str=new StringBuilder("");
        int len=str.length();
        while(len!=30) {
            tmp_str.append("0");
            len++;
        }
        tmp_str.append(str);
        return tmp_str;
    }

    private static int binarySearchPM(int[] arr, int key){
        int n = arr.length;
        int mid = -1;
        int begin = 0,end=n;
        while(begin <= end){
            mid = (begin+end) / 2;
            if(mid == n){
                return n;
            }
            if(key < arr[mid]){
                end = mid-1;
            } else if(key > arr[mid]){
                begin = mid+1;
            } else {
                return mid;
            }
        }
        //System.out.println(begin+" "+end);
        return -begin; //expected Index
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
}

//package proje;

import java.util.*;

public class limbo
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int year = s.nextInt();

		int sum=0;

		if(year%4==0 && year%100!=0)
		{
			year+=28;
			System.out.println(year);
		}
		else
		{
			while(true)
			{
				if(year%4==0 && year%100!=0 )
					sum+=366;
				else
					sum+=365;
				++year;
				if(sum%7==0)
				{
				System.out.println(	year);
				break;
				}

			}
		}
	}
}

import java.io.*;
import java.util.*;

public class tmp1 {

    public static InputReader in;
    public static PrintWriter out;
    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        boolean leap = (n%400 == 0) && (n%4 == 0 && n%100 != 0);
        if(leap) {
            out.println(n+28);
            out.close();
            return;
        }
        boolean even = (n%2 == 0);
        if(even) {
            out.println(n+11);
            out.close();
            return;
        }
        n++;
        leap = (n%400 == 0) && (n%4 == 0 && n%100 != 0);
        out.println(leap?n+10: n+5);
        out.close();
    }

    static class Node implements Comparable<Node>{
        int num, freq, idx;

        public Node (int u, int v, int idx) {
            this.num = u;
            this.freq = v;
            this.idx = idx;
        }

        public void print() {
            out.println(num + " " + freq + " " + idx);
        }

        public int compareTo(Node n) {
            if(this.freq == n.freq)
                return Integer.compare(this.num, n.num);
            return Integer.compare(-this.freq, -n.freq);
        }
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author evgen
 */
public class class1 {
    public static void main(String args[])
{InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int god=in.nextInt();
        boolean cod=false;
        int y=0;
        if(!((god%4==0&&god%100!=0)||god%400==0)){
        while(!cod)
        {
        if((god%4==0&&god%100!=0)||god%400==0){y+=366;}
        else{y+=365;}

        god++;
        if(y%7==0&&!((god%4==0&&god%100!=0)||god%400==0)){cod=true;}
        }   }

        if(((god%4==0&&god%100!=0)||god%400==0)&&!cod)
        {
         while(!cod)
        {
        if((god%4==0&&god%100!=0)||god%400==0){y+=366;}
        else{y+=365;}

        god++;
        if(y%7==0&&(god%4==0&&god%100!=0)||god%400==0){cod=true;}
        }
        }
out.print(god);
        out.close();}
static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
}}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    public static void main(String[] args) throws java.lang.Exception {
        Reader pm =new Reader();
        //Scanner pm = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int t = 1;
        while(t-- > 0){
            long n = pm.nextInt();
            if(n % 4 == 0 || n % 4 == 0){
                System.out.println(n+28);
            } else {
                long div = n%4;
                if(div == 0)
                    System.out.println(n+28);
                else if(div == 1)
                    System.out.println(n+6);
                else
                    System.out.println(n+11);
            }
        }

    }

    static int countInRange(int arr[], int n, int x, int y) {
        // initialize result
        int count = 0;
        count = upperIndex(arr, n, y) -
                lowerIndex(arr, n, x) + 1;
        return count;
    }

    static int lowerIndex(int arr[], int n, int x) {
        int l = 0, h = n - 1;
        while (l <= h)
        {
            int mid = (l + h) / 2;
            if (arr[mid] >= x)
                h = mid - 1;
            else
                l = mid + 1;
        }
        return l;
    }

    // function to find last index <= y
    static int upperIndex(int arr[], int n, int y) {
        int l = 0, h = n - 1;
        while (l <= h)
        {
            int mid = (l + h) / 2;
            if (arr[mid] <= y)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }

    public static StringBuilder dec_to_bin(long n) {
        // decimal to binary upto 30 binaries
        if(n==0) {
            StringBuilder str=new StringBuilder("");
            for(int i=0;i<30;i++) {
                str.append("0");
            }
            return str;
        }
        StringBuilder str=new StringBuilder("");
        while(n!=0) {
            str.append(n%2L);
            n/=2L;
        }
        str=str.reverse();
        StringBuilder tmp_str=new StringBuilder("");
        int len=str.length();
        while(len!=30) {
            tmp_str.append("0");
            len++;
        }
        tmp_str.append(str);
        return tmp_str;
    }

    private static int binarySearchPM(int[] arr, int key){
        int n = arr.length;
        int mid = -1;
        int begin = 0,end=n;
        while(begin <= end){
            mid = (begin+end) / 2;
            if(mid == n){
                return n;
            }
            if(key < arr[mid]){
                end = mid-1;
            } else if(key > arr[mid]){
                begin = mid+1;
            } else {
                return mid;
            }
        }
        //System.out.println(begin+" "+end);
        return -begin; //expected Index
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
}

import java.io.*;
import java.util.*;
public final class edu_round_b
{
    static FastScanner sc=new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out=new PrintWriter(System.out);

	public static void main(String args[]) throws Exception
	{
		int n=sc.nextInt(),curr=1;
		int[] val=new int[200001];
		for(int i=1000;i<=200000;i++)
		{
			val[i]=curr;
			int days=365;
			if(((i%400==0) || (i%4==0 && i%100!=0)))
			{
				days++;
			}
			curr=(((curr+days)%7)==0)?7:((curr+days)%7);
		}
		int ans=-1;
		for(int i=n+1;i<=200000;i++)
		{
			if(val[i]==val[n] && ((i%4==0 && n%4==0) || (i%4!=0 && n%4!=0)))
			{
				ans=i;
				break;
			}
		}
		out.println(ans);
		out.close();
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

/**
 * @(#)SameCal.java
 *
 *
 * @author Suyash Bhalla
 * @version 1.00 2016/6/13
 */
import java.io.*;
import java.util.*;

public class SameCal{

    public static void main(String args[])throws IOException{

    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    	int N=Integer.parseInt(br.readLine());
    	boolean isLeap=false;

    	while(true){
    		isLeap=false;
    		if(checkYear(N)==2){
    			isLeap=true;
    			N+=28;
    		}else{
    			N+=6;
    		}
    		if((isLeap&&checkYear(N)==2)||(!isLeap)){
    			break;
    		}

    	}

    	System.out.println(N);

    }

    public static int checkYear(int N){
    	if((N%100==0&&N%400==0)||(N%100!=0&&N%4==0)){
    		return 2;
    	}else{
    		return 1;
    	}
    }

}

import java.util.*;

/**
 * Created by m.shakhan on 20.06.2016.
 */
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int y = in.nextInt();
        Calendar cur = Calendar.getInstance();
        cur.set(y, Calendar.MARCH, 1);
        Calendar next = Calendar.getInstance();
        next.set(y + 1, Calendar.MARCH, 1);
        while (cur.get(Calendar.DAY_OF_WEEK) != next.get(Calendar.DAY_OF_WEEK)
                || cur.getActualMaximum(Calendar.DAY_OF_YEAR) != next.getActualMaximum(Calendar.DAY_OF_YEAR)) {
            next.set(Calendar.YEAR, next.get(Calendar.YEAR) + 1);
        }
        System.out.println(next.get(Calendar.YEAR));
    }

}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    //---------------------------------------------------------------------------

    static boolean f(int n) {
        boolean b = false;
        if (n % 4 != 0) {
            b = false;
        } else if (n % 100 != 0) {
            b = true;
        } else if (n % 400 != 0) {
            b = true;
        } else {
            b = true;
        }
        return b;
    }

    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        //-----------------------------------------------------------------------
        int n = in.nextInt();
        boolean fn = f(n);
        int x = 0;
        for (int i = n + 1; i < 10000001; i++) {
            if (f(i)) {
                x++;
            }
            x++;
            if (x % 7 == 0 && fn == f(i)) {
                out.println(i);
                break;
            }
        }
        //-----------------------------------------------------------------------
        out.close();
    }
    //---------------------------------------------------------------------------

    static class Pair implements Comparator {

        int first, second;

        public Pair() {

        }

        public Pair(int f, int s) {
            this.first = f;
            this.second = s;
        }

        @Override
        public int compare(Object o1, Object o2) {
            Pair p1 = (Pair) o1;
            Pair p2 = (Pair) o2;
            int ret = -Integer.compare(p1.first, p2.first);
            if (ret == 0) {
                ret = -Integer.compare(p1.second, p2.second);
            }
            return ret;
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char[] nextCharArray() {
            return next().toCharArray();
        }

        public boolean hasNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String s = reader.readLine();
                    if (s == null) {
                        return false;
                    }
                    tokenizer = new StringTokenizer(s);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }

        public void skipLine() {
            try {
                tokenizer = null;
                reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;

public class B {
	public static void main(String[] args) throws IOException {
		File inputFile = new File("entradaB");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null) {
			int year = Integer.parseInt(line);
			GregorianCalendar c = new GregorianCalendar();
			c.set(year, 5, 13);
			int dayini = c.get(Calendar.DAY_OF_WEEK), dayfin;
			boolean bicini = (year % 400L == 0L) || (year % 4L == 0L && year % 100L != 0L), bicifin;
			do {
				c.add(Calendar.YEAR, 1);
				dayfin = c.get(Calendar.DAY_OF_WEEK);
				year++;
				bicifin = (year % 400L == 0L) || (year % 4L == 0L && year % 100L != 0L);
			} while (dayini != dayfin || bicini != bicifin);
			out.append(year + "\n");
		}
		System.out.print(out);
	}

	static int[] readInts(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		int a[] = new int[st.countTokens()], index = 0;
		while (st.hasMoreTokens())
			a[index++] = Integer.parseInt(st.nextToken());
		return a;
	}

	static long[] readLongs(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		long a[] = new long[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Long.parseLong(st.nextToken());
		return a;
	}

	static double[] readDoubles(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		double a[] = new double[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Double.parseDouble(st.nextToken());
		return a;
	}
}

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class InterviewDate {

    private static int[] daysInMonth = getDaysInMonth();

    public static void main(String [] args){

        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            int startingYear = Integer.parseInt(in.readLine());
            int totalWeeksRemainder = 0;
            int startingIndex = startingYear - 1000;
            for (int i = startingIndex + 1; i < daysInMonth.length; i++) {
                totalWeeksRemainder += daysInMonth[i] % 7;
                if (daysInMonth[i] == daysInMonth[startingIndex] && totalWeeksRemainder % 7 == 0) {
                    System.out.println(i + 1000);
                    break;
                }
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    private static int[] getDaysInMonth() {
        int yearsBefore = 100000 - 1000;
        int[] daysInYear = new int[yearsBefore];

        int curYear = 1000;
        for (int i = 0; i < yearsBefore; i++) {
            if(curYear % 400 == 0 || (curYear % 4 == 0 && curYear % 100 != 0)) {
                daysInYear[i] = 366;
            } else {
                daysInYear[i] = 365;
            }
            curYear++;
        }
        return daysInYear;
    }
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author evgen
 */
public class class1 {
    public static void main(String args[])
{InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int god=in.nextInt();
        boolean cod=false;
        int y=0;
        if(god%4!=0){
        while(!cod)
        {
        if(god%4==0){y+=366;}
        else{y+=365;}
        if(y%7==0){cod=true;}
        god++;
        }   }
        else
        {
         while(!cod)
        {
        if(god%4==0){y+=366;}
        else{y+=365;}

        god++;
        if(y%7==0&&god%4==0){cod=true;}
        }
        }
out.print(god);
        out.close();}
static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
}}

import java.util.Scanner;

public class SameCalendar {
    static boolean isLeap(long year) {
        if ( (year % 400 == 0) || ( year % 4 == 0 && year % 100 != 0) ) return true;
        return false;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long year = scanner.nextLong();
        if (isLeap(year)) {
            System.out.println((year+28));
            return;
        }
        int leapCount = 0;
        for (long y = year+1; y <year+6;y++) {
            if (isLeap(y)) leapCount++;
        }
        if (leapCount == 1) {
            year +=6;
        }
        else year+= 10;
        System.out.println(year);
        scanner.close();
    }
}

/**
 * @(#)SameCal.java
 *
 *
 * @author Suyash Bhalla
 * @version 1.00 2016/6/13
 */
import java.io.*;
import java.util.*;

public class SameCal{

    public static void main(String args[])throws IOException{

    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    	int N=Integer.parseInt(br.readLine());
    	boolean isLeap=false;

    	while(true){
    		isLeap=false;
    		if(checkYear(N)==2){
    			isLeap=true;
    			N+=28;
    		}else{
    			N+=6;
    		}
    		if((isLeap&&checkYear(N)==2)||(!isLeap&&checkYear(N)==1)){
    			break;
    		}

    	}

    	System.out.println(N);

    }

    public static int checkYear(int N){
    	if((N%100==0&&N%400==0)||(N%100!=0&&N%4==0)){
    		return 2;
    	}else{
    		return 1;
    	}
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Problem2 {

	static int[] numOfGlasses;
	static int N = 10000;
	static int num;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		int n = in.nextInt();
		int check = 0;
		int mod;
		boolean leap = (n % 400 == 0) ||(n %4 == 0 && n%100 != 100);
		if(leap)
		{
			while(true)
			{
				n++;
				leap = (n % 400 == 0) ||(n %4 == 0 && n%100 != 100);
				if( leap )
				{
					mod = 366 % 7;
					check += mod;
				}
				else
				{
					check+=1;
				}

				if(check%7 == 0 && leap)
				{
					break;
				}
			}
		}
		else
		{
			do
			{
				n++;
				if( (n % 400 == 0) ||(n %4 == 0 && n%100 != 100))
				{
					check += 2;
				}
				else
				{
					check += 1;
				}
			}while(check % 7 != 0);
		}

		out.println(n);
		out.close();

	}

	static class InputReader {
	    public BufferedReader reader;
	    public StringTokenizer tokenizer;

	    public InputReader(InputStream stream) {
	        reader = new BufferedReader(new InputStreamReader(stream), 32768);
	        tokenizer = null;
	    }

	    public String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public long nextLong()
	    {
	    	return Long.parseLong(next());
	    }

	}

}

import java.util.*;
public class johny {
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		int y=s.nextInt();
		int flag =0;int cnt=0;
		if(IsLeapYear(y))flag=1;
		for(int i =y+1; ; i++){
			cnt++;
			if(IsLeapYear(i))
				cnt++;
			if(cnt%7==0){
				if(flag==1 && IsLeapYear(i)){
					System.out.println(i);
					break;
				}
				else if(flag==0 && !(IsLeapYear(i))){
						System.out.println(i);
						break;
				}
			}

		}

	}
	public static boolean IsLeapYear(int a){
		if(a%400==0 || a%4==0){
			if(a%100!=0)
				return true;
		}
		return false;
	}
}

import java.util.Scanner;

public final class TheSameCalendarCF {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int index=0;
        boolean isLeap=false;
        if(n%4==0)
            isLeap=true;
        if(isLeap){
            while (true){
                n++;
                if(n%4==1)
                    index+=2;
                else
                    index++;
                index=index%7;
                if(n%4==0 && index==0){
                    System.out.println(n);
                    break;
                }
            }
        }else{
            while (true){
                n++;
                if(n%4==1)
                    index+=2;
                else
                    index++;
                index=index%7;
                if(index==0){
                    System.out.println(n);
                    break;
                }
            }
        }

    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;

public class Second{
	static long mod=1000000007;
	static int leap(int n)
	{
		int f=0;
		if (n%4!=0)
		{
		//then (it is a common year)
		f=0;
		}
	else if (n%100!=0)
		{
		//then (it is a leap year)
		f=1;
		}
	else if (n%400!=0)
		{
		//then (it is a common year)
		f=0;
		}
	else {
		//(it is a leap year)
		f=1;
	}
		return f;
	}
    public static void main(String[] args) throws Exception{
    	 InputReader in = new InputReader(System.in);
    	PrintWriter pw=new PrintWriter(System.out);

    	//int t=in.readInt();
        //	while(t-->0)
        	//{
    	int p[]=new int[100001];
    	int c=0;
    	for(int i=1;i<=100000;i++)
    	{
    		if(leap(i)==1)
    		{
    			p[i]=i+28;
    		}
    		else
    		{
    			if(c==0)
    			{
    				p[i]=i+6;
    			}
    			else
    			{
    				p[i]=i+11;
    			}
    			c++;
    			c%=3;
    		}
    	}
    	int n=in.readInt();
    	/*int f=0;

        	if (n%4!=0)
        		{
        		//then (it is a common year)
        		f=0;
        		}
        	else if (n%100!=0)
        		{
        		//then (it is a leap year)
        		f=1;
        		}
        	else if (n%400!=0)
        		{
        		//then (it is a common year)
        		f=0;
        		}
        	else {
        		//(it is a leap year)
        		f=1;
        	}

    	if(f==1)
		   pw.println((n+28));
    	else
    	{

    		if(leap(n-1)==1)
    		{
    			pw.println((n+6));
    		}
    		else
    		{
    			pw.println((n+11));
    		}
    	}*/
    	pw.println(p[n]);
    	//}

    	pw.close();
    }

public static long gcd(long x,long y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}

public static int gcd(int x,int y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}
public static int abs(int a,int b)
{
	return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
	return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
public static int min(int a,int b)
{
	if(a>b)
		return b;
	else
		return a;
}
public static long max(long a,long b)
{
	if(a>b)
		return a;
	else
		return b;
}
public static long min(long a,long b)
{
	if(a>b)
		return b;
	else
		return a;
}

public static long pow(long n,long p,long m)
{
	 long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
}
public static long pow(long n,long p)
{
	long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    p >>=1;
	    n*=n;
	}
	return result;

}
static class Pair implements Comparable<Pair>
{
	int a,b;
	Pair (int a,int b)
	{
		this.a=a;
		this.b=b;
	}

	public int compareTo(Pair o) {
		// TODO Auto-generated method stub
		if(this.a!=o.a)
		return Integer.compare(this.a,o.a);
		else
			return Integer.compare(this.b, o.b);
		//return 0;
	}
	public boolean equals(Object o) {
        if (o instanceof Pair) {
            Pair p = (Pair)o;
            return p.a == a && p.b == b;
        }
        return false;
    }
    public int hashCode() {
        return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
    }
}

static long sort(int a[],int n)
{  	int b[]=new int[n];
	return mergeSort(a,b,0,n-1);}
static long mergeSort(int a[],int b[],long left,long right)
{ long c=0;if(left<right)
 {   long mid=left+(right-left)/2;
	 c= mergeSort(a,b,left,mid);
	 c+=mergeSort(a,b,mid+1,right);
	 c+=merge(a,b,left,mid+1,right); }
	return c;	 }
static long merge(int a[],int  b[],long left,long mid,long right)
{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right)
{ if(a[i]<=a[j]) {b[k++]=a[i++]; }
else	{ b[k++]=a[j++];c+=mid-i;}}
while (i <= (int)mid - 1)   b[k++] = a[i++];
while (j <= (int)right) b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
	a[i] = b[i];  return c;  }

   static  class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }

//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	//StringBuilder sb=new StringBuilder("");
	 //InputReader in = new InputReader(System.in);
	//PrintWriter pw=new PrintWriter(System.out);
	//String line=br.readLine().trim();

	//int t=Integer.parseInt(br.readLine());
  //	while(t-->0)
  	//{
  	//int n=Integer.parseInt(br.readLine());
	//long n=Long.parseLong(br.readLine());
	//String l[]=br.readLine().split(" ");
  //int m=Integer.parseInt(l[0]);
	//int k=Integer.parseInt(l[1]);
	//String l[]=br.readLine().split(" ");
	//l=br.readLine().split(" ");
	/*int a[]=new int[n];
	for(int i=0;i<n;i++)
	{
		a[i]=Integer.parseInt(l[i]);
	}*/
	   //System.out.println(" ");

	//}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    //---------------------------------------------------------------------------

    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        //-----------------------------------------------------------------------
        int n = in.nextInt();
        int ans = n;
        if (n % 4 != 0) {
            ans = n + 6;
        } else if (n % 100 != 0) {
            ans = n + 28;
        } else if (n % 400 != 0) {
            ans = n + 6;
        } else {
            ans = n + 28;
        }
        boolean b = false;
        if (n % 4 != 0) {
            b = false;
        } else if (n % 100 != 0) {
            b = true;
        } else if (n % 400 != 0) {
            b = true;
        } else {
            b = true;
        }
        boolean c = false;
        if (ans % 4 != 0) {
            c = false;
        } else if (ans % 100 != 0) {
            c = true;
        } else if (ans % 400 != 0) {
            c = true;
        } else {
            c = true;
        }
        if (b == true) {
            if (c != true) {
                ans += 28;
            }
        } else {
            if (c != false) {
                ans += 5;
            }
        }
        out.println(ans);
        //-----------------------------------------------------------------------
        out.close();
    }
    //---------------------------------------------------------------------------

    static class Pair implements Comparator {

        int first, second;

        public Pair() {

        }

        public Pair(int f, int s) {
            this.first = f;
            this.second = s;
        }

        @Override
        public int compare(Object o1, Object o2) {
            Pair p1 = (Pair) o1;
            Pair p2 = (Pair) o2;
            int ret = -Integer.compare(p1.first, p2.first);
            if (ret == 0) {
                ret = -Integer.compare(p1.second, p2.second);
            }
            return ret;
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char[] nextCharArray() {
            return next().toCharArray();
        }

        public boolean hasNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String s = reader.readLine();
                    if (s == null) {
                        return false;
                    }
                    tokenizer = new StringTokenizer(s);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }

        public void skipLine() {
            try {
                tokenizer = null;
                reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;

public class Main {
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer buffer;

    public static boolean isLeap(int year) {
        return year%400 == 0 || (year % 4 ==0 && year % 100 != 0);
    }

    public static void solve() throws IOException {
        int n = ni();
        Calendar c = GregorianCalendar.getInstance();
        c.set(n, 1, 1);

        Calendar c2 = GregorianCalendar.getInstance();
        c2.set(n, 1, 1);

        GregorianCalendar cal = new GregorianCalendar();

        do {
            c2.add(Calendar.YEAR, 1);
        } while (c.get(Calendar.DAY_OF_WEEK) != c2.get(Calendar.DAY_OF_WEEK) || (isLeap(c.get(Calendar.YEAR)) != isLeap(c2.get(Calendar.YEAR))));

        System.out.println(c2.get(Calendar.YEAR));

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    static String next() {
        while (buffer == null || !buffer.hasMoreElements()) {
            try {
                buffer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
            }
        }
        return buffer.nextToken();
    }

    static int ni() {
        return Integer.parseInt(next());
    }

    static long nl() {
        return Long.parseLong(next());
    }

    static double nd() {
        return Double.parseDouble(next());
    }

    static String ns() {
        return next();
    }

    static int[] ni(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; i++)
            res[i] = Integer.parseInt(next());
        return res;
    }

    static long[] nl(int n) {
        long[] res = new long[n];
        for (int i = 0; i < n; i++)
            res[i] = Long.parseLong(next());
        return res;
    }

    static double[] nd(int n) {
        double[] res = new double[n];
        for (int i = 0; i < n; i++)
            res[i] = Double.parseDouble(next());
        return res;
    }

    static String[] ns(int n) {
        String[] res = new String[n];
        for (int i = 0; i < n; i++)
            res[i] = next();
        return res;
    }

}

import java.io.*;
import java.math.*;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 *
 * @author Saju
 *
 */

public class Main {

    private static int dx[] = { 1, 0, -1, 0 };
    private static int dy[] = { 0, -1, 0, 1 };

    private static final long INF = Long.MAX_VALUE;
    private static final int INT_INF = Integer.MAX_VALUE;
    private static final long NEG_INF = Long.MIN_VALUE;
    private static final int NEG_INT_INF = Integer.MIN_VALUE;
    private static final double EPSILON = 1e-10;

    private static final long MAX = (long) 1e12;

    private static final long MOD = 100000007;

    private static final int MAXN = 100;
    private static final int MAXA = 2000007;
    private static final int MAXLOG = 22;
    private static final double PI = Math.acos(-1);

	public static void main(String[] args) throws IOException {

		InputReader in = new InputReader(System.in);
//		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

//         InputReader in = new InputReader(new FileInputStream("src/test.in"));
//         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));

/*

*/

		Calendar gc = new GregorianCalendar();
		int year = in.nextInt();
		gc.set(Calendar.YEAR, year);
        gc.set(Calendar.MONTH, 0);
        gc.set(Calendar.DAY_OF_MONTH, 1);
        int first = gc.get(Calendar.DAY_OF_WEEK);
        gc.set(Calendar.MONTH, 11);
        gc.set(Calendar.DAY_OF_MONTH, 31);
        int last = gc.get(Calendar.DAY_OF_WEEK);
//        System.out.println(first + " " + last);
		for(int i = 1; i <= 400; i++) {
			gc.set(Calendar.YEAR, year + i);
	        gc.set(Calendar.MONTH, 0);
	        gc.set(Calendar.DAY_OF_MONTH, 1);
	        int first1 = gc.get(Calendar.DAY_OF_WEEK);
	        gc.set(Calendar.MONTH, 11);
	        gc.set(Calendar.DAY_OF_MONTH, 31);
	        int last1 = gc.get(Calendar.DAY_OF_WEEK);
	        if(first == first1 && last == last1) {
	        	out.println(year + i);
	        	break;
	        }
		}

		in.close();
		out.flush();
		out.close();
		System.exit(0);
	}

	/*
	 * return the number of elements in list that are less than or equal to the val
	 */
	private static long upperBound(List<Long> list, long val) {
		int start = 0;
		int len = list.size();
		int end = len - 1;
		int mid = 0;

		while (true) {
			if (start > end) {
				break;
			}
			mid = (start + end) / 2;
			long v = list.get(mid);
			if (v == val) {
				start = mid;
				while(start < end) {
					mid = (start + end) / 2;
					if(list.get(mid) == val) {
						if(mid + 1 < len && list.get(mid + 1) == val) {
							start = mid + 1;
						}
						else {
							return mid + 1;
						}
					}
					else {
						end = mid - 1;
					}
				}
				return start + 1;
			}
			if (v > val) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
		}
		if (list.get(mid) < val) {
			return mid + 1;
		}
		return mid;
	}

	private static boolean isPalindrome(String str) {
		StringBuilder sb = new StringBuilder();
		sb.append(str);
		String str1 = sb.reverse().toString();
		return str.equals(str1);
	}

	private static String getBinaryStr(long n, int j) {
		String str = Long.toBinaryString(n);
		int k = str.length();
		for (int i = 1; i <= j - k; i++) {
			str = "0" + str;
		}

		return str;
	}

	private static long modInverse(long r) {
		return bigMod(r, MOD - 2, MOD);
	}

	private static long bigMod(long n, long k, long m) {

        long ans = 1;
        while (k > 0) {
            if ((k & 1) == 1) {
                ans = (ans * n) % m;
            }
            n = (n * n) % m;
            k >>= 1;
        }
        return ans;
    }

	private static long ceil(long n, long x) {
		long div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
	}

    private static int ceil(int n, int x) {
        int div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
    }

    private static int abs(int x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static double abs(double x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static long abs(long x) {
        if(x < 0) {
            return -x;
        }
        return x;
    }

    private static int lcm(int a, int b) {
        return (a * b) / gcd(a, b);
    }

    private static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static long gcd(long a, long b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static int log(long x, int base) {
        return (int) (Math.log(x) / Math.log(base));
    }

    private static long min(long a, long b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static int min(int a, int b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static long max(long a, long b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static int max(int a, int b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());

                }
            } catch (IOException e) {
                return null;
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = null;
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public boolean hasNext() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (Exception e) {
                return false;
            }
            return true;
        }

        public int[] nextIntArr(int n) {
        	int arr[] = new int[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr(int n) {
        	long arr[] = new long[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public int[] nextIntArr1(int n) {
        	int arr[] = new int[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr1(int n) {
        	long arr[] = new long[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public void close() {
        	try {
        		if(reader != null) {
        			reader.close();
        		}
        	}
        	catch(Exception e) {

        	}

        }
    }

}

/*
 * Code Author: Akshay Miterani
 * DA-IICT
 */
import java.io.*;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;

import javax.sound.sampled.SourceDataLine;

public class MainB {

	static double eps=(double)1e-6;
	static long mod=(int)1e9+7;
	public static void main(String args[]){
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		//----------My Code----------
		int n=in.nextInt();
		int nn=n;
		boolean l=leap(n);
		int val=0;
		while(true){
			if(leap(n)){
				val+=2;
			}
			else{
				val+=1;
			}
			if(val%7==0 && leap(n)==l){
				break;
			}
			n++;
		}
		if(leap(nn)){
			int x=(nn/100)%10;
			if(((nn+28)/100)%10==x || (nn+28)%100==0)
				System.out.println(nn+28);
			else
				System.out.println(nn+40);
		}
		else{
			System.out.println(n+1);
		}
		out.close();
		//---------------The End------------------

	}
	static boolean leap(int x){
		if(x%400==0 || (x%4==0 && x%100!=0)){
			return true;
		}
		else{
			return false;
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	//static public class Trie {
	static class TrieNode {
		TrieNode[] children = new TrieNode[128];
		boolean leaf;
	}

	public static void insertString(TrieNode root, String s) {
		TrieNode cur = root;
		for (char ch : s.toCharArray()) {
			if (cur.children[ch] == null) {
				cur.children[ch] = new TrieNode();
			}
			cur = cur.children[ch];
		}
		cur.leaf = true;
	}

	public static void printSorted(TrieNode node, String s) {
		for (char ch = 0; ch < node.children.length; ch++) {
			TrieNode child = node.children[ch];
			if (child != null)
				printSorted(child, s + ch);
		}
		if (node.leaf) {
			System.out.println(s);
		}
	}
	//}
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		int i;
		Pair(int xx,int yy){
			x=xx;
			y=yy;
		}
		@Override
		public int compareTo(Pair o) {
			return Integer.compare(this.x, o.x);

		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

import java.util.*;

public class Main {

	private static Scanner scan = new Scanner(System.in);

	public static void main(String [] args) {

		int y = scan.nextInt();
		GregorianCalendar cal2 = new GregorianCalendar(y, 0, 1);
		int k = cal2.get(Calendar.DAY_OF_WEEK);
		int i;
		for(i=y+1; ; i++) {
			GregorianCalendar cal1 = new GregorianCalendar(i, 0, 1);
			if(cal1.get(Calendar.DAY_OF_WEEK) == k && cal2.isLeapYear(y) == cal1.isLeapYear(i)) {
				break;
			}
		}
		System.out.println(i);
	}

}

//package proje;

import java.util.*;

public class limbo
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int year = s.nextInt();

		int sum=0;

		if(year%4==0)
		{
			year+=28;
			System.out.println(year);
		}
		else
		{
			while(true)
			{
				if(year%4==0)
					sum+=366;
				else
					sum+=365;
				++year;
				if(sum%7==0)
				{
				System.out.println(	year);
				break;
				}

			}
		}
	}
}

import java.io.*;
import java.util.StringTokenizer;

/**
 * Created by Alvin on 7/5/2016.
 */

public class Codeforces_Educational_round_13_TheSameCalendar {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int n = input.nextInt();
        out.println(n % 400 == 0 || n % 4 == 0 ? n + 28 : n + 6);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

        public FScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}

/**
 * @(#)SameCal.java
 *
 *
 * @author Suyash Bhalla
 * @version 1.00 2016/6/13
 */
import java.io.*;
import java.util.*;

public class SameCal{

    public static void main(String args[])throws IOException{

    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    	int N=Integer.parseInt(br.readLine());

    	boolean L=checkYear(N)==2?true:false;
    	int cnt=0;
    	if(L){

    		while(true){
    			cnt+=checkYear(N++);
    			if(cnt%7==0&&checkYear(N)==2){
    				break;
    			}
    		}

    	}else{
    		while(true){
    			cnt+=checkYear(N++);
    			if(cnt%7==0){
    				break;
    			}

    		}
    	}

    	System.out.println(N);
    }

    public static int checkYear(int N){
    	if((N%100==0&&N%400==0)||(N%100!=0&&N%4==0)){
    		return 2;
    	}else{
    		return 1;
    	}
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.time.LocalDate;

public class BeautyCallendar {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter printWriter = new PrintWriter(System.out);
        int n = Integer.parseInt(br.readLine());
        LocalDate c = LocalDate.of(n, 1, 1);
        for (int i = n + 1; i < 100000; i++) {
            if (compare(c, c.plusYears(i - n))) {
                printWriter.print(i);
                break;
            }
        }
        printWriter.flush();
        printWriter.close();
    }

    private static boolean compare(LocalDate c, LocalDate date) {
        if (c.isLeapYear() != date.isLeapYear()) {
            return false;
        }
        for (int i = 0; i < 12; ++i) {
            if(!c.plusMonths(i).getDayOfWeek().equals(date.plusMonths(i).getDayOfWeek())) {
                return false;
            }
        }
        return true;
    }
}

//package proje;

import java.util.*;

public class limbo
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int year = s.nextInt();

		int sum=0;

		if(year%4==0)
		{
			year+=28;
			System.out.println(year);
		}
		else
		{
			while(true)
			{
				if(year%4==0)
					sum+=366;
				else
					sum+=365;

				if(sum%7==0)
				{
				System.out.println(	++year);
				break;
				}

			}
		}
	}
}

import java.io.*;
import java.util.*;

public class tmp1 {

    public static InputReader in;
    public static PrintWriter out;
    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        boolean leap = (n%4 == 0);
        if(n%400 != 0 && n%100 == 0)
            leap = false;
        if(leap) {
            out.println(n+28);
            out.close();
            return;
        }
        boolean even = (n%2 == 0);
        if(even) {
            out.println(n+11);
            out.close();
            return;
        }
        n++;
        leap = (n%4 == 0);
        if(n%400 != 0 && n%100 == 0)
            leap = false;
        out.println(leap?n+10: n+5);
        out.close();
    }

    static class Node implements Comparable<Node>{
        int num, freq, idx;

        public Node (int u, int v, int idx) {
            this.num = u;
            this.freq = v;
            this.idx = idx;
        }

        public void print() {
            out.println(num + " " + freq + " " + idx);
        }

        public int compareTo(Node n) {
            if(this.freq == n.freq)
                return Integer.compare(this.num, n.num);
            return Integer.compare(-this.freq, -n.freq);
        }
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;

public class Main {
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer buffer;

    public static void solve() throws IOException {
        int n = ni();
        Calendar c = GregorianCalendar.getInstance();
        c.set(n, 1, 1);

        Calendar c2 = GregorianCalendar.getInstance();
        c2.set(n, 1, 1);

        GregorianCalendar cal = new GregorianCalendar();

        do {
            c2.add(GregorianCalendar.YEAR, 1);
        } while (c.get(Calendar.DAY_OF_WEEK) != c2.get(Calendar.DAY_OF_WEEK) || (cal.isLeapYear(c.get(Calendar.YEAR)) != cal.isLeapYear(c2.get(Calendar.YEAR))));

        System.out.println(c2.get(Calendar.YEAR));

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    static String next() {
        while (buffer == null || !buffer.hasMoreElements()) {
            try {
                buffer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
            }
        }
        return buffer.nextToken();
    }

    static int ni() {
        return Integer.parseInt(next());
    }

    static long nl() {
        return Long.parseLong(next());
    }

    static double nd() {
        return Double.parseDouble(next());
    }

    static String ns() {
        return next();
    }

    static int[] ni(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; i++)
            res[i] = Integer.parseInt(next());
        return res;
    }

    static long[] nl(int n) {
        long[] res = new long[n];
        for (int i = 0; i < n; i++)
            res[i] = Long.parseLong(next());
        return res;
    }

    static double[] nd(int n) {
        double[] res = new double[n];
        for (int i = 0; i < n; i++)
            res[i] = Double.parseDouble(next());
        return res;
    }

    static String[] ns(int n) {
        String[] res = new String[n];
        for (int i = 0; i < n; i++)
            res[i] = next();
        return res;
    }

}

import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unchecked")
public class P678B {

  boolean isLeap(int y) {
    return ((((y % 4) == 0) && (y % 100) != 0) || ((y % 400) == 0));
  }

  public void run() throws Exception {
    int y = nextInt();
    println(y + (isLeap(y) ? 28 : 6) + (isLeap(y + 4) ? 0 : -1));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P678B().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    return ((b > 0) ? gcd(b, a % b) : a);
  }
}

import java.util.Scanner;

public class sameCalender {
	public static boolean isLeap(int y){

		return ((y%4==0)|| (y%400==0&y%100!=0));
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] days = {"sat","sun","mon","tue","wed","thur","fri"};
		int y = sc.nextInt();
		boolean leap = isLeap(y);
//		System.out.println(leap);
		if(leap){
			System.out.println(y+28);

		}
		else
		{
			int nxt = y+1;
			int count = 1;
			while(true){
				leap = isLeap(nxt);
				if(leap){
					count+=2;
				}
				else
					count++;
				if(days[count%7].equals("sat")){
					System.out.println(nxt+1);
					break;
				}
				nxt++;
			}
		}
	}
}

import java.util.*;

/**
 * Created by m.shakhan on 20.06.2016.
 */
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int y = in.nextInt();
        Calendar cur = Calendar.getInstance();
        cur.set(y, Calendar.MARCH, 1);
        boolean isLeap = y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
        Calendar next = Calendar.getInstance();
        next.set(++y, Calendar.MARCH, 1);
        while (cur.get(Calendar.DAY_OF_WEEK) != next.get(Calendar.DAY_OF_WEEK)
                || isLeap != (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))) {
            next.set(Calendar.YEAR, ++y);
        }
        System.out.println(next.get(Calendar.YEAR));
    }
}

import java.util.Scanner;

public class SameCalendar {
    static boolean isLeap(long year) {
        if ( (year % 400 == 0) || ( year % 4 == 0 && year % 100 != 0) ) return true;
        return false;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long year = scanner.nextLong();
        if (isLeap(year)) {
            System.out.println((year+28));
            return;
        }
        int leapCount = 0;
        for (long y = year+1; y <year+6;y++) {
            if (isLeap(y)) leapCount++;
        }
        if (leapCount == 1) {
            year +=6;
        }
        else year+= 10;
        System.out.println(year);
        scanner.close();
    }
}

import java.io.*;
import java.util.*;

public class tmp1 {

    public static InputReader in;
    public static PrintWriter out;
    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        out.println((n%400 == 0) || (n%4 == 0 && n%100 != 0)? n+28: n+6);
        out.close();
    }

    static class Node implements Comparable<Node>{
        int num, freq, idx;

        public Node (int u, int v, int idx) {
            this.num = u;
            this.freq = v;
            this.idx = idx;
        }

        public void print() {
            out.println(num + " " + freq + " " + idx);
        }

        public int compareTo(Node n) {
            if(this.freq == n.freq)
                return Integer.compare(this.num, n.num);
            return Integer.compare(-this.freq, -n.freq);
        }
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Foobaf {
    public static class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    private static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }

    private static long lcm(long a, long b) {
        return (a * b) / gcd(a, b);
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int y = fs.nextInt();

        Pairy2[] years = new Pairy2[100001];
        for (int i = 0; i < years.length; ++i) {
            years[i] = new Pairy2();
            if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
                years[i].isLeap = 366;
            }
            else {
                years[i].isLeap = 365;
            }
        }

        years[1000].day = 2;
        int days = 0;
        for (int i = 1000; i < 100000; ++i) {
            days += years[i].isLeap;
            years[i + 1].day = (days) % 7;
        }

        for (int l = y + 1; ; ++l) {
            if (years[l].isLeap == years[y].isLeap && years[l].day == years[y].day) {
                System.out.println(l);
                return;
            }
        }
    }

    private static class Pairy2 {
        int isLeap;
        int day;
    }
}

/**
 * @(#)SameCal.java
 *
 *
 * @author Suyash Bhalla
 * @version 1.00 2016/6/13
 */
import java.io.*;
import java.util.*;

public class SameCal{

    public static void main(String args[])throws IOException{

    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    	int N=Integer.parseInt(br.readLine());
    	boolean isLeap=false;

    	while(true){
    		isLeap=false;
    		if(checkYear(N)==2){
    			isLeap=true;
    			N+=28;
    		}else{
    			N+=6;
    		}
    		if((isLeap&&checkYear(N)==2)||(!isLeap)){
    			break;
    		}

    	}

    	System.out.println(N);

    }

    public static int checkYear(int N){
    	if((N%100==0&&N%400==0)||(N%100!=0&&N%4==0)){
    		return 2;
    	}else{
    		return 1;
    	}
    }

}

import java.util.Scanner;

public class Main {
  static int y;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    y = sc.nextInt();

    int yy = y + 1, count = 1;
    if(!isLeapYear(y)){
      while((count % 7) != 0){
        if(isLeapYear(yy)){
          ++count;
        }
        ++count;  ++yy;
      }
    }
    else{
      ++count;
      while(!((count % 7) == 0 && isLeapYear(yy))){
        if(isLeapYear(yy)){
          ++count;
        }
        ++count;  ++yy;
      }
    }

    System.out.println(yy);
  }

  private static boolean isLeapYear(int year){
    if(year % 4 == 0){
      if(year % 100 == 0){
        if(year % 400 == 0){
          return true;
        }
        else{
          return false;
        }
      }
      else{
        return true;
      }
    }
    else{
      return false;
    }
  }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Problem2 {

	static int[] numOfGlasses;
	static int N = 10000;
	static int num;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		int n = in.nextInt();
		int check = 0;
		int mod;
		boolean leap = (n % 400 == 0) ||(n %4 == 0 && n%100 != 0);
		if(leap)
		{
			while(true)
			{
				n++;
				leap = (n % 400 == 0) ||(n %4 == 0 && n%100 != 0);
				if( leap )
				{
					mod = 366 % 7;
					check += mod;
				}
				else
				{
					check+=1;
				}

				if(check%7 == 0 && leap)
				{
					break;
				}
			}
		}
		else
		{
			do
			{
				n++;
				if( (n % 400 == 0) ||(n %4 == 0 && n%100 != 0))
				{
					check += 2;
				}
				else
				{
					check += 1;
				}
			}while(check % 7 != 0);
		}

		out.println(n);
		out.close();

	}

	static class InputReader {
	    public BufferedReader reader;
	    public StringTokenizer tokenizer;

	    public InputReader(InputStream stream) {
	        reader = new BufferedReader(new InputStreamReader(stream), 32768);
	        tokenizer = null;
	    }

	    public String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public long nextLong()
	    {
	    	return Long.parseLong(next());
	    }

	}

}

import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
        String next() { while (st == null || !st.hasMoreElements()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (IOException e) { e.printStackTrace(); } }
                return st.nextToken();
            }

        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }

        String nextLine() {
            String str = "";
            try { str = br.readLine(); }
            catch (IOException e) { e.printStackTrace(); }
            return str;
        }
    }

    static boolean isLeapYear(long n){
        if(n%4==0){
            if(n%400==0){
                return true;
            }else if(n%100==0){
                return false;
            }else{
                return true;
            }
        }
            return false;
    }

    public static void main(String[] args) throws IOException {
        FastReader ip = new FastReader();
        OutputStream output = System.out;
        PrintWriter out = new PrintWriter(output);
            long n = ip.nextLong();
            if(isLeapYear(n)){
                out.print(n+28);
            }else {
                if (isLeapYear(n + (4 - (n % 4)))) {
                    out.print(n + 6);
                }else{
                    out.print(n+6);
                }
            }
        out.close();
    }
}

import java.io.*;
import java.util.*;
public final class edu_round_b
{
    static FastScanner sc=new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out=new PrintWriter(System.out);

	public static void main(String args[]) throws Exception
	{
		int n=sc.nextInt(),curr=1;
		int[] val=new int[200001];
		for(int i=1000;i<=200000;i++)
		{
			val[i]=curr;
			int days=365;
			if(((i%400==0) || (i%4==0 && i%100!=0)))
			{
				days++;
			}
			curr=(((curr+days)%7)==0)?7:((curr+days)%7);
		}
		int ans=-1;
		for(int i=n+1;i<=200000;i++)
		{
			if(val[i]==val[n] && ((i%4==0 && n%4==0) || (i%4!=0 && n%4!=0)))
			{
				ans=i;
				break;
			}
		}
		out.println(ans);
		out.close();
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    public static void main(String[] args) throws java.lang.Exception {
        Reader pm =new Reader();
        //Scanner pm = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int t = 1;
        while(t-- > 0){
            long n = pm.nextInt();
            int odd = 0;
            while(true){
                if(((n % 4 == 0) && (n % 100 != 0)) || (n % 400 == 0)) {
                    odd+=2;
                    n++;
                } else {
                    odd++;
                    n++;
                }
                if(odd % 7 == 0){
                    System.out.println(n);
                    return;
                }
            }
        }

    }

    static int countInRange(int arr[], int n, int x, int y) {
        // initialize result
        int count = 0;
        count = upperIndex(arr, n, y) -
                lowerIndex(arr, n, x) + 1;
        return count;
    }

    static int lowerIndex(int arr[], int n, int x) {
        int l = 0, h = n - 1;
        while (l <= h)
        {
            int mid = (l + h) / 2;
            if (arr[mid] >= x)
                h = mid - 1;
            else
                l = mid + 1;
        }
        return l;
    }

    // function to find last index <= y
    static int upperIndex(int arr[], int n, int y) {
        int l = 0, h = n - 1;
        while (l <= h)
        {
            int mid = (l + h) / 2;
            if (arr[mid] <= y)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }

    public static StringBuilder dec_to_bin(long n) {
        // decimal to binary upto 30 binaries
        if(n==0) {
            StringBuilder str=new StringBuilder("");
            for(int i=0;i<30;i++) {
                str.append("0");
            }
            return str;
        }
        StringBuilder str=new StringBuilder("");
        while(n!=0) {
            str.append(n%2L);
            n/=2L;
        }
        str=str.reverse();
        StringBuilder tmp_str=new StringBuilder("");
        int len=str.length();
        while(len!=30) {
            tmp_str.append("0");
            len++;
        }
        tmp_str.append(str);
        return tmp_str;
    }

    private static int binarySearchPM(int[] arr, int key){
        int n = arr.length;
        int mid = -1;
        int begin = 0,end=n;
        while(begin <= end){
            mid = (begin+end) / 2;
            if(mid == n){
                return n;
            }
            if(key < arr[mid]){
                end = mid-1;
            } else if(key > arr[mid]){
                begin = mid+1;
            } else {
                return mid;
            }
        }
        //System.out.println(begin+" "+end);
        return -begin; //expected Index
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
public class aeducational13{

	static boolean leap(long n){
		if(n%4==0){
			if(n%100==0&&n%400==0){return true;}
			else if(n%400!=0&&n%100==0){return false;}
			else {return true;}
		}
		return false;
	}
	public static void main(String[] args) throws Exception
    {
	   //new FileInputStream("input.txt");
		//new FileOutputStream("output.txt")
		InputReader in = new InputReader(System.in);
		OutputWriter out = new OutputWriter(System.out);
		long y=in.rl();
		if(leap(y)==true)out.pl(y+28);
		else
		{
			//out.pl("else");
			int d = 0;
			do {
				d++;
				if (leap(y)) d++;
				y++;
				d %= 7;
			} while (d>0 || leap(y) == true);
			out.pl(y);
		}
	    out.close();
	}
private static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				} catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (numChars <= 0)
				return -1;
			}
			return buf[curChar++];
		}

		public String rs()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

		public int ri()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public double rd() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, ri());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, ri());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

		public long rl() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}

	private static class OutputWriter
	{
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream)
		{
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer)
		{
			this.writer = new PrintWriter(writer);
		}
 		public void print(Object... objects)
		{
			for (int i = 0; i < objects.length; i++)
			{
				if (i != 0)
				writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void pf(double n)
		{
			writer.printf("%.2f%n", n);
		}
		public void pl(Object... objects)
		{
			print(objects);
			writer.println();
		}

		public void close()
		{
			writer.close();
		}

		public void flush()
		{
			writer.flush();
		}

	}
}

//package proje;

import java.util.*;

public class limbo
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int year = s.nextInt();

		int sum=0;

		if(year%4==0)
		{
			year+=28;
			System.out.println(year);
		}
		else
		{
			while(true)
			{
				if(year%4==0)
					sum+=366;
				else
					sum+=365;

				if(sum%7==0)
				{
				System.out.println(	++year);
				break;
				}

			}
		}
	}
}

/*-
 * Codeforces problem :
 * http://codeforces.com/problemset/problem/678/B
 *
 * Print the only integer y' — the next year after
 * y when the calendar will be the same. Note that
 * you should find the first year after y with the
 * same calendar.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Karthik Venkataraman
 * @email kafy83@gmail.com
 */
public class SameCalendar {

    private InputReader sc = new InputReader(System.in);
    private PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    private boolean isLeap(int y) {
        return y % 400 == 0 || (y % 4 == 0 && y % 100 > 0);
    }

    private void compute() {
        int n = sc.nextInt(), d = 0;
        if (isLeap(n)) {
            pw.print(n + 28);
            pw.flush();
        }
        for (;;) {
            d = isLeap(n++) ? (d + 2) % 7 : (d + 1) % 7;
            if (d == 0 && !isLeap(n)) {
                break;
            }
        }
        pw.print(n);
        pw.flush();
    }

    class InputReader {

        private static final int INPUT_KB = 1024;
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), INPUT_KB);
        }

        String readNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    throw new IllegalStateException(ex);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(readNext());
        }
    }

    public static void main(String... args) {
        SameCalendar sca = new SameCalendar();
        sca.compute();
    }
}

import java.io.*;
import java.util.*;

/**
 * @author Alexander Tsupko (alexander.tsupko[at]outlook.com) (c) All rights reserved, June 14, 2016.
 */
public class B {
    private static class Solve {
        private int FIRST_DAY = 1;
        private int FIRST_MONTH = 1;

        private void solve(int testNumber, InputReader in, PrintWriter out) {
//            long startTime = System.nanoTime();

            int year = in.nextInt();

            int firstDayWhichDayOfTheWeek = whichDayOfTheWeek(FIRST_DAY, FIRST_MONTH, year);
            int lastDayWhichDayOfTheWeek;
            if (isLeap(year)) {
                lastDayWhichDayOfTheWeek = firstDayWhichDayOfTheWeek + 1;
            } else {
                lastDayWhichDayOfTheWeek = firstDayWhichDayOfTheWeek;
            }

            int firstDayOfThisYearWhichDayOfTheWeek;
            int lastDayOfThisYearWhichDayOfTheWeek;
            do {
                ++year;
                firstDayOfThisYearWhichDayOfTheWeek = whichDayOfTheWeek(FIRST_DAY, FIRST_MONTH, year);
                if (isLeap(year)) {
                    lastDayOfThisYearWhichDayOfTheWeek = firstDayOfThisYearWhichDayOfTheWeek + 1;
                } else {
                    lastDayOfThisYearWhichDayOfTheWeek = firstDayOfThisYearWhichDayOfTheWeek;
                }
            } while (firstDayOfThisYearWhichDayOfTheWeek != firstDayWhichDayOfTheWeek
                    || lastDayOfThisYearWhichDayOfTheWeek != lastDayWhichDayOfTheWeek);

            out.println(year);

//            long estimatedTime = System.nanoTime() - startTime;
//            out.printf(Locale.US, "%.1f ms\n", estimatedTime/1e6);
        }

        private boolean isLeap(int year) {
            return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
        }

        private int whichDayOfTheWeek(int day, int month, int year) {
            int m = month + 10;
            int y = --year % 100;
            int c = year / 100;
            int W = day + (13 * m - 1) / 5 + y + y / 4 + c / 4 - 2 * c;
            return W % 7;
        }
    }

    private static class InputReader {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        private InputReader(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 32768);
        }

        private void close() throws IOException {
            bufferedReader.close();
        }

        private String nextLine() {
            try {
                return bufferedReader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        private String next() {
            while (stringTokenizer == null || !stringTokenizer.hasMoreTokens())
                stringTokenizer = new StringTokenizer(nextLine());
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solve solve = new Solve();
        solve.solve(1, in, out);
//        int testCount = Integer.parseInt(in.next());
//        for (int i = 1; i <= testCount; i++) solve.solve(i, in, out);
        in.close();
        out.close();
    }
}

import java.util.Scanner;

public class sameCalender {
	public static boolean isLeap(int x){

		 return x%400==0 || (x%4==0 && x%100!=0);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] days = {"sat","sun","mon","tue","wed","thur","fri"};
		int y = sc.nextInt();
		boolean leap = isLeap(y);
//		System.out.println(leap);
		if(leap){
//			System.out.println(y+28);
//			int nxt = y+1;
			int nxt=y;
			int res = 0;
			int val = 0;
			do{
				val = isLeap(nxt)?1:0;
				res= (res+365+val)%7;
				nxt++;
			}while( (res!=0) || isLeap(nxt)!=isLeap(y));
			System.out.println(nxt);
		}
		else
		{
			int nxt = y+1;
			int count = 1;
			while(true){
				leap = isLeap(nxt);
				if(leap){
					count+=2;
				}
				else
					count++;
				if(days[count%7].equals("sat")){
					System.out.println(nxt+1);
					break;
				}
				nxt++;
			}
		}
	}
}

import java.util.Scanner;

public class SameCalendar {
    static boolean isLeap(long year) {
        if ( (year % 400 == 0) || ( year % 4 == 0 && year % 100 != 0) ) return true;
        return false;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long year = scanner.nextLong();
        if (isLeap(year)) {
            System.out.println((year+28));
            return;
        }
        int leapCount = 0;
        for (long y = year+1; y <year+6;y++) {
            if (isLeap(y)) leapCount++;
        }
        if (leapCount == 1) {
            year +=6;
        }
        else year+= 10;
        System.out.println(year);
        scanner.close();
    }
}

/*-
 * Codeforces problem :
 * http://codeforces.com/problemset/problem/678/B
 *
 * Print the only integer y' — the next year after
 * y when the calendar will be the same. Note that
 * you should find the first year after y with the
 * same calendar.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Karthik Venkataraman
 * @email kafy83@gmail.com
 */
public class SameCalendar {

    private InputReader sc = new InputReader(System.in);
    private PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    private boolean isLeap(int y) {
        return y % 400 == 0 || (y % 4 == 0 && y % 100 > 0);
    }

    private void compute() {
        int n = sc.nextInt(), d = 0;
        boolean stleap = isLeap(n);
        for (;;) {
            d = isLeap(n) ? (d + 2) % 7 : (d + 1) % 7;
            if (d == 0 && stleap == isLeap(++n)) {
                break;
            }
        }
        pw.print(n);
        pw.flush();
    }

    class InputReader {

        private static final int INPUT_KB = 1024;
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), INPUT_KB);
        }

        String readNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    throw new IllegalStateException(ex);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(readNext());
        }
    }

    public static void main(String... args) {
        SameCalendar sca = new SameCalendar();
        sca.compute();
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;

public class Second{
	static long mod=1000000007;
	static int leap(int n)
	{
		int f=0;
		if (n%4!=0)
		{
		//then (it is a common year)
		f=0;
		}
	else if (n%100!=0)
		{
		//then (it is a leap year)
		f=1;
		}
	else if (n%400!=0)
		{
		//then (it is a common year)
		f=0;
		}
	else {
		//(it is a leap year)
		f=1;
	}
		return f;
	}
    public static void main(String[] args) throws Exception{
    	 InputReader in = new InputReader(System.in);
    	PrintWriter pw=new PrintWriter(System.out);

    	//int t=in.readInt();
        //	while(t-->0)
        	//{
    	int p[]=new int[100001];
    	int c=0;
    	for(int i=1;i<=100000;i++)
    	{
    		if(i%2800==0)
    			c=0;
    		if(leap(i)==1)
    		{
    			p[i]=i+28;
    		}
    		else
    		{
    			int x=i+5;
    			if(leap(x)==1)
    			{
    				p[i]=i+11;
    			}
    			else
    			{
    				p[i]=i+6;
    			}
    		}
    	}
    	int n=in.readInt();
    	/*int f=0;

        	if (n%4!=0)
        		{
        		//then (it is a common year)
        		f=0;
        		}
        	else if (n%100!=0)
        		{
        		//then (it is a leap year)
        		f=1;
        		}
        	else if (n%400!=0)
        		{
        		//then (it is a common year)
        		f=0;
        		}
        	else {
        		//(it is a leap year)
        		f=1;
        	}

    	if(f==1)
		   pw.println((n+28));
    	else
    	{

    		if(leap(n-1)==1)
    		{
    			pw.println((n+6));
    		}
    		else
    		{
    			pw.println((n+11));
    		}
    	}*/
    	pw.println(p[n]);
    	//}

    	pw.close();
    }

public static long gcd(long x,long y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}

public static int gcd(int x,int y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}
public static int abs(int a,int b)
{
	return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
	return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
public static int min(int a,int b)
{
	if(a>b)
		return b;
	else
		return a;
}
public static long max(long a,long b)
{
	if(a>b)
		return a;
	else
		return b;
}
public static long min(long a,long b)
{
	if(a>b)
		return b;
	else
		return a;
}

public static long pow(long n,long p,long m)
{
	 long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
}
public static long pow(long n,long p)
{
	long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    p >>=1;
	    n*=n;
	}
	return result;

}
static class Pair implements Comparable<Pair>
{
	int a,b;
	Pair (int a,int b)
	{
		this.a=a;
		this.b=b;
	}

	public int compareTo(Pair o) {
		// TODO Auto-generated method stub
		if(this.a!=o.a)
		return Integer.compare(this.a,o.a);
		else
			return Integer.compare(this.b, o.b);
		//return 0;
	}
	public boolean equals(Object o) {
        if (o instanceof Pair) {
            Pair p = (Pair)o;
            return p.a == a && p.b == b;
        }
        return false;
    }
    public int hashCode() {
        return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
    }
}

static long sort(int a[],int n)
{  	int b[]=new int[n];
	return mergeSort(a,b,0,n-1);}
static long mergeSort(int a[],int b[],long left,long right)
{ long c=0;if(left<right)
 {   long mid=left+(right-left)/2;
	 c= mergeSort(a,b,left,mid);
	 c+=mergeSort(a,b,mid+1,right);
	 c+=merge(a,b,left,mid+1,right); }
	return c;	 }
static long merge(int a[],int  b[],long left,long mid,long right)
{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right)
{ if(a[i]<=a[j]) {b[k++]=a[i++]; }
else	{ b[k++]=a[j++];c+=mid-i;}}
while (i <= (int)mid - 1)   b[k++] = a[i++];
while (j <= (int)right) b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
	a[i] = b[i];  return c;  }

   static  class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }

//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	//StringBuilder sb=new StringBuilder("");
	 //InputReader in = new InputReader(System.in);
	//PrintWriter pw=new PrintWriter(System.out);
	//String line=br.readLine().trim();

	//int t=Integer.parseInt(br.readLine());
  //	while(t-->0)
  	//{
  	//int n=Integer.parseInt(br.readLine());
	//long n=Long.parseLong(br.readLine());
	//String l[]=br.readLine().split(" ");
  //int m=Integer.parseInt(l[0]);
	//int k=Integer.parseInt(l[1]);
	//String l[]=br.readLine().split(" ");
	//l=br.readLine().split(" ");
	/*int a[]=new int[n];
	for(int i=0;i<n;i++)
	{
		a[i]=Integer.parseInt(l[i]);
	}*/
	   //System.out.println(" ");

	//}
}

import java.io.*;
import java.util.*;

public class tmp1 {

    public static InputReader in;
    public static PrintWriter out;
    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        boolean leap = (n%400 == 0) || (n%4 == 0 && n%100 != 0);
        if(leap) {
            out.println(n+28);
            out.close();
            return;
        }
        boolean even = (n%2 == 0);
        if(even) {
            out.println(n+11);
            out.close();
            return;
        }
        n++;
        leap = (n%400 == 0) || (n%4 == 0 && n%100 != 0);
        out.println(leap?n+10: n+5);
        out.close();
    }

    static class Node implements Comparable<Node>{
        int num, freq, idx;

        public Node (int u, int v, int idx) {
            this.num = u;
            this.freq = v;
            this.idx = idx;
        }

        public void print() {
            out.println(num + " " + freq + " " + idx);
        }

        public int compareTo(Node n) {
            if(this.freq == n.freq)
                return Integer.compare(this.num, n.num);
            return Integer.compare(-this.freq, -n.freq);
        }
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}