N = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

ans = 0
for i in range(1, N):
    a1[i] = a1[i-1] + a1[i]
    a2[N-i-1] = a2[N-i] + a2[N-i-1]

for i in range(N):
    ans = max(ans, a1[i] + a2[i])

print(ans)


f = lambda :list(map(int,input().split()))
N = int(input())
A1 = f()
A2 = f()

dp = [[0 for i in range(N)] for j in range(2)]

dp[0][0] = A1[0]
dp[1][0] = dp[0][0] + A2[0]

for i in range(1,N):
    dp[0][i] = dp[0][i-1] + A1[i]
for j in range(1,N):
    dp[1][j] = max((dp[0][j], dp[1][j-1])) + A2[j]

print(dp[1][N-1])


N = int(input())
P = [list(map(int,input().split())) for _ in range(2)]
ans = sum(P[0]) + P[1][N-1]
p = ans

for i in range(N-1, 0, -1):
    p = p - P[0][i] + P[1][i-1]
    ans = max(p, ans)

print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = 0
for i in range(n):
  c = 0
  for j in range(n):
    if j <= i:
      c += a[j]
    else:
      c += b[j]
  res = max(res,c)
print(res)


N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
C = []

S = sum(A2) + A1[0]

for i in range(1,N):
  C.append(S)
  S += A1[i]-A2[i-1]

print(max(C))


n=int(input())
a=list(map(int,input().split()))
b=list(map(int, input().split()))
ans = 0
        for i in range(n):
                        ans = max(ans,sum(a[:i+1])+sum(b[i:n]))


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{

    void solve() {
     int n=2;
     int m=ni();
     int a[][]=new int[n+1][m+1];
     for(int i=1;i<=n;i++){
         for(int j=1;j<=m;j++) a[i][j]=ni();
     }
     int dp[][]=new int[n+1][m+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                dp[i][j]=a[i][j]+Math.max(dp[i-1][j],dp[i][j-1]);
            }
        }
        pw.println(dp[n][m]);

    }

    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

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

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}


import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args) throws IOException
	{
		Reader in=new Reader();
		int n=in.nextInt();
		int a[][]=new int[n][2];
		int prea[][]=new int[n][2];
		int max=0;
		for(int i=0; i<n; i++)
		{
			a[i][0]=in.nextInt();
		}
		for(int i=0; i<n; i++)
		{
			a[i][1]=in.nextInt();
		}
		prea[0][0]=a[0][0];
		prea[0][1]=a[0][1];
		for(int i=1; i<n; i++)
		{
			prea[i][0]=a[i][0]+prea[i-1][0];
			prea[i][1]=a[i][1]+prea[i-1][1];
		}
		max=prea[n-1][1]+a[0][0];
	//	System.out.println(prea[n-1][0]+" "+prea[n-1][1]);
		for(int i=1; i<n; i++)
		{
	//		System.out.println(prea[i][0]-prea[i-1][1]+prea[n-1][1]);
			max=Math.max(prea[i][0]-prea[i-1][1]+prea[n-1][1], max);
		}
		System.out.println(max);
	}
	static StringBuilder ans=new StringBuilder();
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
        StringTokenizer st;

        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 next() throws IOException
        {
        	while(st==null||!st.hasMoreElements())
        	{
        		try
        		{
        			st=new StringTokenizer(readLine());
        		}
        		catch(IOException e)
        		{
        			e.printStackTrace();
        		}
        	}
        	return
        			st.nextToken();
        }
        public String readLine() throws IOException
        {
            byte[] buf = new byte[65535]; // 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 l() 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.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[][] A = new int[3][N + 1];
		for (int i = 1; i <= N; i++)
			A[1][i] = sc.nextInt();
		for (int i = 1; i <= N; i++)
			A[2][i] = sc.nextInt();

		int max = 0;
		for (int i = 1; i <= N; i++) {
			int s = 0;
			for (int j = 1; j <= i; j++)
				s += A[1][j];
			for (int k = i; k <= N; k++)
				s += A[2][k];
			max = Math.max(max, s);
		}

		System.out.println(max);
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

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

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

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

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

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a1 = new int[n+1];
        int[] a2 = new int[n];

        for(int i=0; i<n; i++) {
            a1[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++) {
            a2[i] = sc.nextInt();
        }

        int a1Sum = 0;
        for(int i=1; i<n; i++) {
            a1Sum += a1[i];
        }

        int a2Sum = 0;
        for(int i=0; i<n-1; i++) {
            a2Sum += a2[i];
        }

        int cnt = 0;
        for(int i=0; i<n; i++) {
            if(a1Sum >= a2Sum) {
                cnt += a1[i];
                a1Sum -= a1[i+1];
                a2Sum -= a2[i];
            } else {
                cnt = a1[i] + a2Sum;
                break;
            }
        }
        System.out.println(cnt+a2[n-1]);
    }
}


import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a1 = new int[n+1];
        int[] a2 = new int[n];

        for(int i=0; i<n; i++) {
            a1[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++) {
            a2[i] = sc.nextInt();
        }

        int a1Sum = 0;
        for(int i=1; i<n; i++) {
            a1Sum += a1[i];
        }

        int a2Sum = 0;
        for(int i=0; i<n-1; i++) {
            a2Sum += a2[i];
        }

        int cnt = 0;
        for(int i=0; i<n; i++) {
            if(a1Sum >= a2Sum) {
                cnt += a1[i];
                a1Sum -= a1[i+1];
                a2Sum -= a2[i];
            } else {
                cnt += a1[i] + a2Sum;
                break;
            }
        }
        System.out.println(cnt+a2[n-1]);
    }
}


import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {

  static int x,y,n;
  static int sum,ans;
  static int[][] a;

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

    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < n; j++) {
        a[i][j] = sc.nextInt();
      }
    }

    x = 0; y = 0;
    sum = 0;
    ans = Integer.MIN_VALUE;

    dfs(x,y);

    System.out.println(ans);

  }

  public static boolean dfs (int i, int j) {

    if (i < 0 || i >=n || j < 0 || j >= 2) {
      return false;
    }

    sum += a[j][i];

    if (i == n-1 && j == 1) {
      ans = Math.max(sum,ans);
      sum = 0;
    }

    if (dfs(i+1,j)) return true;

    if (dfs(i,j+1)) return true;

    return false;

  }

}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;

  int A[2][110];
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> A[i][j];
    }
  }

  int total = A[0][0] + A[1][N-1];
  for (int i = 0; i < N-1; ++i) {
    total += A[1][i];
  }

  int ans = total;
  for (int i = 1; i < N; ++i) {
    total += -A[1][i-1] + A[0][i];
    ans = max(ans, total);
  }

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));

  for(int i=0; i<n; i++){
    cin >> a.at(0).at(i);
  }
  for(int i=0; i<n; i++){
    cin >> a.at(1).at(i);
  }

  vector<int> candy(n, 0);
  for(int i=0; i<n; i++){
    for(int j=0; j<=i; j++) candy.at(i)+=a.at(0).at(j);
    for(int j=i; j<n; j++) candy.at(i)+=a.at(1).at(j);
  }

  sort(candy.begin(), candy.end());
  cout << candy.at(n-1) << endl;
}


#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A[2][100];
    cin >> N;
    REP(i, 2) {
        REP(j, N) {
            cin >> A[i][j];
        }
    }
    int res = 0;
    REP(i, N) {
        int sum = 0;
        REP(j, N) {
            if (j < i) {
                sum += A[0][j];
            } else if (j > i) {
                sum += A[1][j];
            } else {
                sum += A[0][j] + A[1][j];
            }
        }
        amax(res, sum);
    }
    cout << res << endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define Fast ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(i, n) for(i=0; i<n; i++)
#define fort(i, n) for(i=1; i<=n; i++)
const int inf=1e9,mod=1e9+7,N=2e5+5;

using namespace std;
template<class T> void umax(T &a,T b){a=max(a,b);}
int pref[2][N];
int main()
{
	Fast;
	int n;
	cin >> n;
	int arr[2][n+1], i, j;
	rep(i, n){
		fort(j, n){
			cin >> arr[i][j];
			if(j==1) pref[i][j] = arr[i][j];
			else pref[i][j] = pref[i][j-1] + arr[i][j];
		}
	}
	int ans = 0;
	fort(i, n){
		umax(ans,pref[0][i]+pref[1][n-1]-pref[1][i-1]+arr[1][n]);
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define ll long long
#define pb push_back
#define Fast ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(i, n) for(i=0; i<n; i++)
#define fort(i, n) for(i=1; i<=n; i++)
const int inf=1e9,mod=1e9+7,N=2e5+5;
template<class T> void umax(T &a,T b){a=max(a,b);}
using namespace std;
int pref[2][N];
int main()
{
	Fast;
	int n;
	cin >> n;
	int arr[2][n+1], i, j;
	rep(i, n){
		fort(j, n){
			cin >> arr[i][j];
			if(j==1) pref[i][j] = arr[i][j];
			else pref[i][j] = pref[i][j-1] + arr[i][j];
		}
	}
	int ans = 0;
	fort(i, n){
		umax(ans,pref[0][i]+pref[1][n-1]-pref[1][i-1]+arr[1][n]);
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define ll long long
#define pb push_back
#define Fast ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(i, n) for(i=0; i<n; i++)
#define fort(i, n) for(i=1; i<=n; i++)
const int inf=1e9,mod=1e9+7,N=2e5+5;
template<class T> void umax(T &a,T b){a=max(a,b);}
using namespace std;
int pref[2][N];
int main()
{
	Fast;
	int n;
	cin >> n;
	int arr[2][n+1], i, j;
	rep(i, n){
		fort(j, n){
			cin >> arr[i][j];
			if(j==1) pref[i][j] = arr[i][j];
			else pref[i][j] = pref[i][j-1] + arr[i][j];
		}
	}
	int ans = 0;
	fort(i, n){
		umax(ans,pref[0][i]+pref[1][n-1]-pref[1][i-1]+a[1][n]);
	}
	cout << ans << endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define mod 1000000007
#define limit 200001
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i = 0; i < n; i++)
#define max(a,b) {if(a>b){return a;}return b;}
#define min(a,b) {if(a<b){return a;}return b;}

int main(){
    int n,i,j;
    int tmp = 0;
    int under_point = 0;
    int max_value = 0;
    int a[2][100];

    scanf("%d",&n);
    rep(i,n) scanf("%d",&a[0][i]);
    rep(j,n) scanf("%d",&a[1][j]);

    for(i = 0; i < n; i++){
        for(j = 0; j < under_point; j++) tmp += a[0][j];
        tmp += a[0][under_point];
        tmp += a[1][under_point];
        for(j = under_point+1; j < n; j++) tmp += a[1][j];
        if(tmp > max_value){
            max_value = tmp;
//            printf("max = %d\n",max_value);
        }
        tmp = 0;
        under_point++;
    }

    printf("%d\n",max_value);
}


#include <stdio.h>
#define max(x, y)  ((x)<(y) ? (y) : (x))

int main(){
  int n;  scanf("%d", &n);
  int field[2][102];
  field[0][0] = field[1][0] = 0;
  for(int i=0; i<2; i++)
    for(int j=1; j<=n; j++){
      int cand;  scanf("%d", &cand);
      field[i][j] = field[i][j-1] + cand;
    }
  int ans = 0;
  for(int i=1; i<=n; i++){
    int score = field[0][i] + (field[1][n] - field[1][i-1]);
    ans = max(ans, score);
  }
  printf("%d\n", ans);
  return 0;
}


#include <stdio.h>

int main(void) {

  int n;
  scanf("%d", &n);
  int a[2][n];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int sum[2][n];
  sum[0][0] = a[0][0];
  for (int i = 1; i < n; i++) {
    sum[0][i] = sum[0][i-1]+a[0][i];
  }
  int max;
  sum[1][0] = sum[0][0]+a[1][0];
  for (int i = 1; i < n; i++) {
    max = sum[0][i];
    if (sum[1][i-1] > max) {
      max = sum[1][i-1];
    }
    sum[1][i] = max+a[1][i];
  }
  printf("%d\n", sum[1][n-1]);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int compare_int_reverse(const void *a, const void *b);

int main(void)
{
	int i;
	int n;
	char *p;
	int alice, bob;
	int a[128];
	char buffer[4096];

	// read input
	scanf("%d\n",&n);
	fgets(buffer, sizeof buffer-1, stdin);
	//printf("%d %s",n,buffer);

	p=buffer;
	for (i=0;i<n;++i)
	{
		a[i]=strtol(p,&p,10);
		//printf("\ta[%d]=%d\n",i,a[i]);
	}

	// sort
	qsort(a,n,sizeof (int), compare_int_reverse);

	// sum for Alice and Bob
	alice=0;
	bob=0;
	for (i=0;i<n;++i)
	{
		if ((i&1)==0)
		{
			alice+=a[i];
		}
		else
		{
			bob+=a[i];
		}
	}

	//printf("\tAlice: %d\n",alice);
	//printf("\tBob: %d\n",bob);
	printf("%d\n",alice-bob);

	return 0;
}

int compare_int_reverse(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}


#include<stdio.h>

int main()
{
  int n;

  scanf("%d",&n);

  int a[2][n];
  int i,j;

  for(i=0;i<2;i++)
  {
    for(j=0;j<n;j++)
    {
      scanf("%d",&a[i][j]);
    }
  }

  int sum_1=0,sum_2=0,ans;

  ans=a[0][0]+a[1][n-1];
  j=0;

  while(j<n-1)
  {
    for(i=j;i<n-1;i++)
    {
      sum_1+=a[0][i+1];
    }

    for(i=j;i<n;i++)
    {
      sum_2+=a[1][i];
    }

    if(sum_1>=sum_2)
    {
      ans+=a[0][j+1];
    }
    else
    {
      ans+=a[1][j];
    }
    j++;
  }

 printf("%d\n",ans);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int Max(int a, int b) {
	return a < b ? b : a;
}

int main(void) {
	int n, c,grid[2][51] = {0};
	scanf("%d", &n);

	for (int i = 0; i < 2; i++) {
		for (int j = 1; j <= n; j++) {
			scanf("%d", &c);
			if (i == 0) {
				grid[i][j] = grid[i][j - 1] + c;
			}
			else {
				grid[i][j] = Max(grid[i][j - 1], grid[i - 1][j]) + c;
			}
		}
	}
	printf("%d\n", grid[1][n]);
}


function main(input) {
  const lines = input.split("\n");
  const N = parseInt(lines.shift());

  const upper = lines.shift().split(' ').map(x => parseInt(x));
  const downer = lines.shift().split(' ').map(x => parseInt(x));

  const cum_up = [upper[0]];
  const cum_down = [downer[0]];

  if (N==1){
    console.log(upper[0] + downer[0]);
    return
  }
  for(var i=1;i<N;i++){
    cum_up.push(cum_up[i-1]+upper[i])
    cum_down.push(cum_down[i-1]+downer[i])
  }

  var result = cum_up[0]+cum_down[N-1];
  for(var i=1;i<N;i++){
    var current = cum_up[i]+cum_down[N-1]-cum_down[i-1]
    if (current > result){result = current;}
  }

  console.log(result);

//  console.log(upper);
//  console.log(cum_up);

//  console.log(downer);
//  console.log(cum_down);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


// inputに入力データ全体が入る
function Main(input) {

  var inp = input.split('\n');
  var N = inp[0];
  var tmp = inp[1].split(' ');
  var tmp2 = inp[2].split(' ');
  var A = new Array;
  A[0] = new Array;
  A[1] = new Array;

  for (var j = 0; j < N; j++) {
    A[0][j] = parseInt(tmp[j]);
    A[1][j] = parseInt(tmp2[j]);
  }

  var maxVal = 0;
  for (var tmp = 0; tmp <= N - 1; tmp++) {
    var sum = 0;
    for (var l = 0; l <= N - 1 - tmp; l++) {
      sum += A[0][l];
    }
    for (var m = N - 1 - tmp; m <= N - 1; m++) {
      sum += A[1][m];
    }
    if (sum > maxVal) maxVal = sum;
  }
  console.log('%d', maxVal);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt();
    let A0 = new Array(N);
    let A1 = new Array(N);
    for (let n = 0; n < N; n++) A0[n] = cin.getInt();
    for (let n = 0; n < N; n++) A1[n] = cin.getInt();
    for (let n = 1; n < N; n++) {
        A0[n] += A0[n - 1];
        A1[N - n - 1] += A1[N - n];
    }
    let ans = 0;
    for (let n = 0; n < N; n++) {
        let s = A0[n] + A1[n];
        if (ans < s) ans = s;
    }
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0;this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));


"use strict";

const main = arg => {
    arg = arg.split("\n");
    const N     = ~~arg[0];
    const table = arg.slice(1, 3).map(n=>n.split(" ").map(l=>~~l));

    const topLowSum    = table[0].reduce((m,n)=>m+n);
    const bottomLowSum = table[1].reduce((m,n)=>m+n);

    let answer = 0;
    let pivot;

    for(let i=0; i<N; i++) {
        let top  = topLowSum - table[0].slice(0, i + ~~1).reduce((m,n)=>m+n) + table[1][N-1];
        let down = i === 0 ? bottomLowSum : bottomLowSum - table[1].slice(0, i).reduce((m,n)=>m+n);

        if(down > top) {
            pivot = i;
            break;
        }
    }

    if(pivot !== undefined) {
        const beforePivot = table[0].slice(0, pivot + 1).reduce((m,n)=>m+n);
        const afterPivot  = table[1].slice(pivot, N).reduce((m,n)=>m+n);

        console.log(beforePivot + afterPivot);
    } else {
        console.log(topLowSum + table[1][N-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N     = ~~arg[0];
    const table = arg.slice(1, 3).map(n=>n.split(" ").map(l=>~~l));

    const topLowSum    = table[0].reduce((m,n)=>m+n);
    const bottomLowSum = table[1].reduce((m,n)=>m+n);

    let answer = 0;
    let pivot;

    for(let i=0; i<N; i++) {
        let top  = topLowSum - table[0].slice(0, i + ~~1).reduce((m,n)=>m+n) + table[1][N-1];
        let down = i === 0 ? bottomLowSum : bottomLowSum - table[1].slice(0, i).reduce((m,n)=>m+n);

        if(down > top) {
            pivot = i;
            break;
        }
    }

    if(pivot !== undefined) {
        const beforePivot = table[0].slice(0, pivot + 1).reduce((m,n)=>m+n);
        const afterPivot  = table[1].slice(pivot, N).reduce((m,n)=>m+n);

        console.log(beforePivot + afterPivot);
    } else {
        console.log(topLowSum + table[1][N-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N     = ~~arg[0];
    const table = arg.slice(1, 3).map(n=>n.split(" ").map(l=>~~l));

    const topLowSum    = table[0].reduce((m,n)=>m+n);
    const bottomLowSum = table[1].reduce((m,n)=>m+n);

    let answer = 0;
    let pivot;

    console.log(bottomLowSum)

    for(let i=0; i<N; i++) {
        let top  = topLowSum - table[0].slice(0, i + ~~1).reduce((m,n)=>m+n) + table[1][N-1];
        let down = i === 0 ? bottomLowSum : bottomLowSum - table[1].slice(0, i).reduce((m,n)=>m+n);

        if(down > top) {
            pivot = i;
            break;
        }
    }

    if(pivot !== undefined) {
        const beforePivot = table[0].slice(0, pivot + 1).reduce((m,n)=>m+n);
        const afterPivot  = table[1].slice(pivot, N).reduce((m,n)=>m+n);

        console.log(beforePivot + afterPivot);
    } else {
        console.log(topLowSum + table[1][N-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var n int
var A [][]int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	A = make([][]int, 2)
	for i := 0; i < n; i++ {
		tmp := nextInt()
		A[0] = append(A[0], tmp)
	}
	sum := 0
	for i := 0; i < n; i++ {
		tmp := nextInt()
		sum += tmp
		A[1] = append(A[1], tmp)
	}

	upsum := make([]int, n)
	downsum := make([]int, n)
	upsum[0] = A[0][0]
	downsum[0] = sum

	ans := -1
	for i := 0; i < n; i++ {
		if upsum[i]+downsum[i] > ans {

			ans = upsum[i] + downsum[i]
		}
		if i < n-1 {
			upsum[i+1] = upsum[i] + A[0][i+1]
			downsum[i+1] = downsum[i] - A[1][i]
		}
	}

	fmt.Println(ans)
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

// const (
// 	initialBufSize = bufio.MaxScanTokenSize //65536
// 	maxBufSize     = 100000
// )
func main() {
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, initialBufSize)
	// scanner.Buffer(buf, maxBufSize)

	n := nextInt()
	a1 := make([]int, n)
	a2 := make([]int, n)
	for i := range a1 {
		a1[i] = nextInt()
	}
	for i := range a2 {
		a2[i] = nextInt()
	}

	max := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j <= i; j++ {
			sum += a1[j]
		}
		for k := i; k < n; k++ {
			sum += a2[k]
		}
		if sum > max {
			max = sum
		}
	}
	fmt.Println(max)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := getInt()
	a1 := getIntSlice(n)
	a2 := getIntSlice(n)

	ans := -1
	for i := 0; i < n; i++ {
		s := sum(a1[0:i+1]...) + sum(a2[i:n]...)
		ans = max(ans, s)
	}

	fmt.Fprintln(wr, ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intMax(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	A := [2][]int{}
	A[0], A[1] = make([]int, N), make([]int, N)
	for i := 1; i < N; i++ {
		A[0][i] += A[0][i-1]
	}
	for i := N - 2; i >= 0; i-- {
		A[1][i] += A[1][i+1]
	}

	ans := 0
	for i := 0; i < N; i++ {
		ans = intMax(ans, A[0][i]+A[1][i])
	}

	fmt.Println(ans)
}


package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([][]int, 2)
	t := [2]int{0, 0}
	for i := 0; i < 2; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[i][j])
			t[i] += a[i][j]
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j <= i; j++ {
			sum += a[0][j]
		}
		for j := i + 1; j < n; j++ {
			sum += a[1][j]
		}

		if ans < sum {
			ans = sum
		}
	}

	fmt.Println(ans)
}


package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	m := make([][]int, 2)
	for i := 0; i < 2; i++ {
		n := make([]int, N)
		for j := 0; j < N; j++ {
			fmt.Scan(&n[j])
		}
		m[i] = n
	}
	wa := make([][]int, 2)
	a := make([]int, N)
	a[N-1] = m[1][N-1]
	for j := N - 1; j > 0; j-- {
		a[j-1] = m[1][j-1] + a[j]
	}
	wa[1] = a

	a = make([]int, N)
	for i := 1; i < N; i++ {
		a[i] = m[0][i] + wa[1][i]
	}
	wa[0] = a

	r := m[0][0]
	for i := 0; i < N; i++ {
		if i+1 == N {
			r += wa[1][N-1]
			break
		}
		if wa[0][i+1] > wa[1][i+1] {
			r += m[0][i+1]
		} else {
			fmt.Println("した")
			r += wa[1][i]
			break
		}
	}
	fmt.Println(r)

}


n = gets.to_i
as = 2.times.map{gets.chomp.split.map(&:to_i)}

dp = Array.new(2){Array.new(n,0)}
dp[0][0] = as[0][0]
dp[1][0] = dp[0][0] + as[1][0]
(0..n-2).each do |i|
	dp[0][i+1] = dp[0][i] + as[0][i+1]
	dp[1][i+1] = [dp[1][i] + as[1][i+1], dp[0][i+1] + as[1][i+1]].max
end

puts dp[1][n-1]


def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end
N=gets.to_i
a=array(2)
2.times do|i|
    a[i]=get_i
end
dp=array(N,0,2)
dp[0][0]=a[0][0]
2.times do|i|
    N.times do|j|
        next if i.zero? and j.zero?
        if i-1>=0
            dp[i][j]=max(dp[i][j],dp[i-1][j]+a[i][j])
        end
        if j-1>=0
            dp[i][j]=max(dp[i][j],dp[i][j-1]+a[i][j])
        end
    end
end
puts dp[1][N-1]


n = gets.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

suma=0
sumb=0
n.times do |i|
  suma += a[i]
  sumb += b[i]
end

suma += b[n-1]
sumb += a[0]

if suma > sumb then
  ans=suma
else
  ans=sumb
end

tmpsuma=a[0]
tmpsumb=sumb-a[0]
for i in 1..n-1 do
  if i==0 then
    i = 1
  end
  tmpsuma += a[i]
  tmpsumb -= b[i-1]
  if tmpsuma+tmpsumb > ans then
    ans = tmpsuma+tmpsumb
  end
end

puts ans


n=gets.to_i
up,under=2.times.map{gets.split.map(&:to_i)}
a=0

for i in 1...n-1
    v1=up[0..i].inject(&:+)
    v2=under[i..-1].inject(&:+)
    if v1+v2>a
        a=v1+v2
    end

end
puts a


lines = readlines.join.split.map(&:to_i)
range = lines.shift
ary = []
2.times do
    ary << lines.slice!(0..range-1)
end
ans = []
for i in 0..range do
    ans << (ary[0].slice(0..i)).push(ary[1].slice(i..range-1))
end
ans.map!{|t| t.flatten}
ans.map!{|f| f.sum }
p ans.max


lines = readlines.join.split.map(&:to_i)
range = lines.shift
ary = []
2.times do
    ary << lines.slice!(0..range-1)
end
ans = []
for i in 0..range do
    ans << (ary[0].slice(0..i)).append(ary[1].slice(i..range-1))
end
ans.map!{|t| t.flatten}
ans.map!{|f| f.sum }
p ans.max


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        a1: [i64; n],
        a2: [i64; n],
    };
    println!(
        "{}",
        (0..n)
        .map(|i|{
            (0..i+1).map(|i| a1[i]).sum::<i64>() +
            (i..n).map(|i| a2[i]).sum::<i64>()
        })
        .max().unwrap()
    );
}


use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<Vec<usize>> = (0..2)
        .map(|_| {
            (0..n)
                .map(|_| itr.next().unwrap().parse().unwrap())
                .collect()
        })
        .collect();

    let mut ans = 0;
    for i in 0..n {
        let mut tmp = 0;
        let mut k = 0;
        for j in 0..n {
            tmp += a[k][j];
            if i == j {
                tmp += a[k + 1][j];
                k += 1;
            }
        }
        ans = std::cmp::max(ans, tmp);
    }
    println!("{}", ans);
}


use std::io;

fn read_grid() -> Vec<Vec<i32>> {
    //! load stdio input like below.
    //! ```
    //! 2
    //! 2 3
    //! 4 5
    //! ```
    let mut line = String::new();
    let mut inputs = Vec::<Vec<char>>::new();
    io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<i32>();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let first_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let second_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    vec![first_line, second_line]
}

fn solve(grid: Vec<Vec<i32>>) -> i32 {
    let mut max_all = 0;
    for k in 1..(grid[0].len() + 1) {
        let start = grid[0][0];
        let first_sum: i32 = grid[0][..k].iter().sum();
        let second_sum: i32 = grid[1][(k - 1)..].iter().sum();
        let sum = first_sum + second_sum;

        if sum > max_all {
            max_all = sum;
        }
    }
    let first_sum: i32 = grid[0].iter().sum();
    let second_sum: i32 = grid[1][grid[0].len() - 1];
    let sum = first_sum + second_sum;
    if sum > max_all {
        max_all = sum;
    }
    return max_all;
}

fn main() {
    let inputs = read_grid();
    let res = solve(inputs);
    println!("{}", res);
}


use std::io;

fn read_grid() -> Vec<Vec<i32>> {
    //! load stdio input like below.
    //! ```
    //! 2
    //! 2 3
    //! 4 5
    //! ```
    let mut line = String::new();
    let mut inputs = Vec::<Vec<char>>::new();
    io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<i32>();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let first_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let second_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    vec![first_line, second_line]
}

fn solve(grid: Vec<Vec<i32>>) -> i32 {
    let mut max_all = 0;
    for k in 0..grid[0].len() {
        let start = grid[0][0];
        let first_sum: i32 = grid[0][..k].iter().sum();
        let second_sum: i32 = grid[1][k..].iter().sum();
        let sum = first_sum + second_sum + start;

        if sum > max_all {
            max_all = sum;
        }
    }
    let first_sum: i32 = grid[0].iter().sum();
    let second_sum: i32 = grid[1][grid[0].len() - 1];
    let sum = first_sum + second_sum;
    if sum > max_all {
        max_all = sum;
    }
    return max_all;
}

fn main() {
    let inputs = read_grid();
    let res = solve(inputs);
    println!("{}", res);
}


use std::io;

fn read_grid() -> Vec<Vec<i32>> {
    //! load stdio input like below.
    //! ```
    //! 2
    //! 2 3
    //! 4 5
    //! ```
    let mut line = String::new();
    let mut inputs = Vec::<Vec<char>>::new();
    io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<i32>();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let first_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let second_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    vec![first_line, second_line]
}

fn solve(grid: Vec<Vec<i32>>) -> i32 {
    let mut max_all = 0;
    for k in 0..grid[0].len() {
        let start = grid[0][0];
        let first_sum: i32 = grid[0][..k].iter().sum();
        let second_sum: i32 = grid[1][k..].iter().sum();
        let sum = first_sum + second_sum + start;

        if sum > max_all {
            max_all = sum
        }
    }
    let first_sum: i32 = grid[0].iter().sum();
    let second_sum: i32 = grid[1][grid[0].len() - 1];
    let sum = first_sum + second_sum;
    if sum > max_all {
        max_all = sum
    }
    return max_all;
}

fn main() {
    let inputs = read_grid();
    let res = solve(inputs);
    println!("{}", res);
}


use std::io;

fn read_grid() -> Vec<Vec<i32>> {
    //! load stdio input like below.
    //! ```
    //! 2
    //! 2 3
    //! 4 5
    //! ```
    let mut line = String::new();
    let mut inputs = Vec::<Vec<char>>::new();
    io::stdin().read_line(&mut line).unwrap();
    let n = line.trim().parse::<i32>();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let first_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let second_line: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    vec![first_line, second_line]
}

fn solve(grid: Vec<Vec<i32>>) -> i32 {
    let mut max_all = 0;
    for k in 0..grid[0].len() {
        let start = grid[0][0];
        let first_sum: i32 = grid[0][..k].iter().sum();
        let second_sum: i32 = grid[1][k..].iter().sum();
        let sum = first_sum + second_sum + start;

        if sum > max_all {
            max_all = sum
        }
    }
    return max_all;
}

fn main() {
    let inputs = read_grid();
    let res = solve(inputs);
    println!("{}", res);
}


// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {

    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt

    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2

        if Int(ary[mid])! < key {
            left = mid

        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }

    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret
}

func main() {
    let n = readInt()
    let table = [readInts(),readInts()]
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var remUnder = table[1].reduce(0) { $0 + $1 }

    var ans = 0
    var left = 0
    for i in 0..<n {
        left += table[0][i]
        ans = max(ans, remUnder + left)
        remUnder -= table[1][i]
    }
    print(ans)
}
main()


let N = Int(readLine()!)!
let A1 = readLine()!.characters.split(" ").map{Int(String($0))!}
let A2 = readLine()!.characters.split(" ").map{Int(String($0))!}
var sumA1 = A1[0]
var sumA2 = A2.reduce(0){$0+$1}
var ans = sumA1 + sumA2
for i in 1..<N {
    sumA1 += A1[i]
    sumA2 -= A2[i-1]
    ans = max(sumA1 + sumA2, ans)
}
print(ans)


// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {

    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt

    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2

        if Int(ary[mid])! < key {
            left = mid

        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }

    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret
}

func main() {
    let n = readInt()
    let table = [readInts(),readInts()]
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var remOver = table[0].reduce(0) { $0 + $1 }
    var remUnder = table[1].reduce(0) { $0 + $1 }
    var ans = 0

    var isOver = true

    for i in 0..<n {
        ans += table[0][i]
        remOver -= table[0][i]
        if remOver + table[1][n - 1] < remUnder {
            ans += remUnder
            isOver = false
            break
        }
        remUnder -= table[1][i]
    }

    print(isOver ? ans + table[1][n - 1]: ans)
}
main()


// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {

    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt

    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2

        if Int(ary[mid])! < key {
            left = mid

        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }

    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret
}

func main() {
    let n = readInt()
    var table = [readInts(),readInts()]
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var remOver = table[0].reduce(0) { $0 + $1 }
    var remUnder = table[1].reduce(0) { $0 + $1 }

    var ans = 0

    for i in 0..<n {
        ans += table[0][i]
        if remOver - table[0][i] < remUnder {
            ans += remUnder
            break
        }
        remOver -= table[0][i]
        remUnder -= table[1][i]
    }

    print(ans)
}
main()


// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {

    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt

    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2

        if Int(ary[mid])! < key {
            left = mid

        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }

    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret
}

func main() {
    let n = readInt()
    var table = [readInts(),readInts()]
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var remOver = table[0].reduce(0) { $0 + $1 }
    var remUnder = table[1].reduce(0) { $0 + $1 }

    print(remOver,remUnder)
    var ans = 0

    for i in 0..<n {
        ans += table[0][i]
        if remOver - table[0][i] < remUnder {
            ans += remUnder
            break
        }
        remOver -= table[0][i]
        remUnder -= table[1][i]
    }

    print(ans)
}
main()


function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const n = parseInt(readMany(1)[0])
    const a = []
    a.push(readMany(n).map(it => parseInt(it)))
    a.push(readMany(n).map(it => parseInt(it)))

    let max = 0

    for (let i = 0; i < n; i += 1) {
        let candies = 0
        for (let j = 0; j <= i; j += 1) candies += a[0][j]
        for (let j = i; j < n; j += 1) candies+= a[1][j]
        if (candies > max) max = candies
    }

    console.log(max)
})()


const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _n = stdin.split('\n')[0]
const n = Number(_n)

const a1 = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)
const a2 = stdin
  .split('\n')[2]
  .split(' ')
  .map(Number)

const a1Total = i => {
  let sum = 0
  for (let j = 0; j <= i; j++) {
    sum += a1[j]
  }
  return sum
}

const a2Total = i => {
  let sum = 0
  for (let j = i; j < a2.length; j++) {
    sum += a2[j]
  }
  return sum
}

const res = _ => {
  let max = 0
  for (let i = 0; i < n; i++) {
    const sum = a1Total(i) + a2Total(i)
    max = sum > max ? sum : max
  }
  return max
}

console.log(res())


{
  const run = (input: string) => {
    let splitted = input.trim().split("\n")
    const n = parseInt(splitted[0])

    const first = splitted[1].trim().split(" ").map(v => parseInt(v))
    const second = splitted[2].trim().split(" ").map(v => parseInt(v))

    let firstSum = first.reduce((a: number, x: number) => a + x) + second[n - 1]
    let secondSum = second.reduce((a: number, x: number) => a + x)

    let sum = 0
    let tmpSum = 0
    let tmpFirstSum = 0
    for (let i = 0; i < n; i++) {
      tmpSum = firstSum > secondSum ? tmpFirstSum + firstSum : tmpFirstSum + secondSum;
      if (sum < tmpSum) sum = tmpSum

      tmpFirstSum += first[i]
      firstSum -= first[i]
      if (second[i - 1] != null) secondSum -= second[i - 1]
    }

    return sum
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}


{
  const run = (input: string) => {
    let splitted = input.trim().split("\n")
    const n = parseInt(splitted[0])

    const first = splitted[1].trim().split(" ").map(v => parseInt(v))
    const second = splitted[2].trim().split(" ").map(v => parseInt(v))

    let firstSum = first.reduce((a, x) => a + x)
    let secondSum = second.reduce((a, x) => a + x)

    let sum = 0

    for (let i = 0; i < n; i++) {
      sum += first[i]
      firstSum -= first[i]

      if (second[i - 1] != null) {
        secondSum -= second[i - 1]
      }

      if (first[i + 1] == null || firstSum < secondSum) {
        return sum + secondSum
      }
    }

    return sum
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}


function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const n = parseInt(readMany(1)[0])
    const a = []
    a.push(readMany(n).map(it => parseInt(it)))
    a.push(readMany(n).map(it => parseInt(it)))

    let candies = [] // i 列目で下に移動したときのアメ

    for (let i = 0; i < n; i += 1) {
        candies[i] = 0
        for (let j = 0; j <= i; j += 1) candies[i] += a[0][j]
        for (let j = i; j < n; j += 1) candies[i] += a[1][j]
    }

    candies = candies.sort()

    console.log(candies[candies.length - 1])
})()


function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const n = parseInt(readMany(1)[0])
    const a = []
    a.push(readMany(n).map(it => parseInt(it)))
    a.push(readMany(n).map(it => parseInt(it)))

    let candies = [] // i 列目で下に移動したときのアメ

    let firstRow = 0 // 上だけの場合の数
    for (let i = 0; i < n; i += 1) {
        firstRow += a[0][i]
        candies = candies.map(it => it + a[1][i])
        candies.push(firstRow + a[1][i])
    }

    candies = candies.sort()

    console.log(candies[candies.length - 1])
})()


n,k=map(int,input().split())
s=n-(1*k)+1
if k==1:
  print(0)
else:
  print(s-1)


N, K = map(int, input().split())

if K==1:
  print(0)
else:
  print(N-K)


N, K = map(int, input().split())

if K == 1 : print(0)
else : print(N - K)


n,k=map(int,input().split())
if k == 1:
  print(n)
else:
  print(n-k)


n,k=map(int,input().split())
if k==1:print(0)
elif n>k:print(n-k)


n, k = map(int, input().split())
ans = n-k if k > 1 else 0


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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), k = fs.nextInt();
		if(k==1)System.out.println(0);
		else System.out.println(n-k);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

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

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


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

public class Main {

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

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);

		if (k != 1)
			System.out.println(n - k);
		else
			System.out.println("0");
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	private static void solve() {
		int n=ni();
		int k=ni();
		if(k==1)kil(0);
		out(n-k);
	}

	static void out(String val) {
		IO.out(val);
	}

	static void out(Object val) {
		IO.out(String.valueOf(val));
	}

	static void out(int val) {
		IO.out(String.valueOf(val));
	}

	static void out(long val) {
		IO.out(String.valueOf(val));
	}

	static void out(char val) {
		IO.out(String.valueOf(val));
	}

	static void out(double val) {
		IO.out(Double.isFinite(val) ? BigDecimal.valueOf(val).toPlainString() : String.valueOf(val));
	}

	static void out(boolean val) {
		IO.out(val ? "true" : "false");
	}

	static void kil(String val) {
		IO.out(val);
		IO.flush();
		System.exit(0);
	}

	static void kil(Object val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(int val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(long val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(char val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(double val) {
		IO.out(Double.isFinite(val) ? BigDecimal.valueOf(val).toPlainString() : String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(boolean val) {
		IO.out(val ? "true" : "false");
		IO.flush();
		System.exit(0);
	}

	static String ns() {
		return IO.next();
	}

	static int ni() {
		return IO.nextInt();
	}

	static long nl() {
		return IO.nextLong();
	}

	static double nd() {
		return IO.nextDouble();
	}

	static char nc() {
		return IO.nextChar();
	}

	static String[] nss(int n) {
		String[] as = new String[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.next();
		}
		return as;
	}

	static int[] nis(int n) {
		int[] as = new int[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.nextInt();
		}
		return as;
	}

	static long[] nls(int n) {
		long[] as = new long[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.nextLong();
		}
		return as;
	}

	static double[] nds(int n) {
		double[] as = new double[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.nextDouble();
		}
		return as;
	}

	static char[] ncs(int n) {
		char[] as = new char[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.nextChar();
		}
		return as;
	}

	static String[][] nss2(int n, int m) {
		String[][] as = new String[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.next();
			}
		}
		return as;
	}

	static int[][] nis2(int n, int m) {
		int[][] as = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.nextInt();
			}
		}
		return as;
	}

	static long[][] nls2(int n, int m) {
		long[][] as = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.nextLong();
			}
		}
		return as;
	}

	static double[][] nds2(int n, int m) {
		double[][] as = new double[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.nextDouble();
			}
		}
		return as;
	}

	static char[][] ncs2(int n, int m) {
		char[][] as = new char[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.nextChar();
			}
		}
		return as;
	}

	static int parseInt(String val) {
		return Integer.parseInt(val);
	}

	static long parseLong(String val) {
		return Long.parseLong(val);
	}

	public static void main(String[] args) {
		try {
			solve();
			IO.flush();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
	}
}

final class IO {
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out, false);
	private static final byte[] buffer = new byte[1024];
	private static int ptr = 0;
	private static int len = 0;

	private static boolean hasNextByte() {
		if (ptr < len)
			return true;
		ptr = 0;
		try {
			len = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return len > 0;
	}

	private static int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	static boolean hasNext() {
		byte c;
		while (hasNextByte() && ((c = buffer[ptr]) < '!' || c > '~'))
			ptr++;
		return hasNextByte();
	}

	static String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (b >= '!' && b <= '~') {
			sb.append((char) b);
			b = readByte();
		}
		return sb.toString();
	}

	static char nextChar() {
		if (!hasNext())
			throw new NoSuchElementException();
		return (char) readByte();
	}

	static long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}

	static int nextInt() {
		if (!hasNext())
			throw new NoSuchElementException();
		int n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}

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

	static void out(String val) {
		out.println(val);
	}

	static void flush() {
		out.flush();
	}
}

// TODO: paste library here
class UP<A, B> { // Unordered Pair
	A a;
	B b;

	UP(A a, B b) {
		this.a = a;
		this.b = b;
	}

	static <A, B> UP<A, B> make(A a, B b) {
		return new UP<A, B>(a, b);
	}

	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof UP))
			return false;
		UP<?, ?> p = (UP<?, ?>) o;
		boolean aok = a == null ? p.a == null : a.equals(p.a);
		boolean bok = b == null ? p.b == null : b.equals(p.b);
		return aok && bok;
	}

	public String toString() {
		return "(" + a.toString() + ", " + b.toString() + ")";
	}
}

class P<A extends Comparable<? super A>, B extends Comparable<? super B>> extends UP<A, B> implements
		Comparable<P<A, B>> { // Pair
	P(A a, B b) {
		super(a, b);
	}

	static <A extends Comparable<? super A>, B extends Comparable<? super B>> P<A, B> make(A a, B b) {
		return new P<A, B>(a, b);
	}

	public int compareTo(P<A, B> o) {
		int sa = a.compareTo(o.a);
		int sb = b.compareTo(o.b);
		return sa != 0 ? sa : sb;
	}
}

class PI implements Comparable<PI> { // Pair int
	int a;
	int b;

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

	static PI make(int a, int b) {
		return new PI(a, b);
	}

	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof PI))
			return false;
		PI p = (PI) o;
		return a == p.a && b == p.b;
	}

	public int compareTo(PI o) {
		int sa = a - o.a;
		int sb = b - o.b;
		return sa > 0 ? 1 : sa < 0 ? -1 : sb > 0 ? 1 : sb < 0 ? -1 : 0;
	}

	public String toString() {
		return "(" + a + ", " + b + ")";
	}
}

class PL implements Comparable<PL> { // Pair long
	long a;
	long b;

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

	static PL make(long a, long b) {
		return new PL(a, b);
	}

	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof PL))
			return false;
		PL p = (PL) o;
		return a == p.a && b == p.b;
	}

	public int compareTo(PL o) {
		long sa = a - o.a;
		long sb = b - o.b;
		return sa > 0 ? 1 : sa < 0 ? -1 : sb > 0 ? 1 : sb < 0 ? -1 : 0;
	}

	public String toString() {
		return "(" + a + ", " + b + ")";
	}
}

class UT<A, B, C> { // Unordered Tuple
	A a;
	B b;
	C c;

	UT(A a, B b, C c) {
		this.a = a;
		this.b = b;
		this.c = c;
	}

	static <A, B, C> UT<A, B, C> make(A a, B b, C c) {
		return new UT<A, B, C>(a, b, c);
	}

	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof UT))
			return false;
		UT<?, ?, ?> t = (UT<?, ?, ?>) o;
		boolean aok = a == null ? t.a == null : a.equals(t.a);
		boolean bok = b == null ? t.b == null : b.equals(t.b);
		boolean cok = c == null ? t.c == null : c.equals(t.c);
		return aok && bok && cok;
	}

	public String toString() {
		return "(" + a.toString() + ", " + b.toString() + ", " + c.toString() + ")";
	}
}

class T<A extends Comparable<? super A>, B extends Comparable<? super B>, C extends Comparable<? super C>> extends
		UT<A, B, C> implements Comparable<T<A, B, C>> { // Tuple
	T(A a, B b, C c) {
		super(a, b, c);
	}

	static <A extends Comparable<? super A>, B extends Comparable<? super B>, C extends Comparable<? super C>> T<A, B, C> make(
			A a, B b, C c) {
		return new T<A, B, C>(a, b, c);
	}

	public int compareTo(T<A, B, C> o) {
		int sa = a.compareTo(o.a);
		int sb = b.compareTo(o.b);
		int sc = c.compareTo(o.c);
		return sa != 0 ? sa : sb != 0 ? sb : sc;
	}
}

class TI implements Comparable<TI> { // Tuple int
	int a;
	int b;
	int c;

	TI(int a, int b, int c) {
		this.a = a;
		this.b = b;
		this.c = c;
	}

	static TI make(int a, int b, int c) {
		return new TI(a, b, c);
	}

	TL toLong() {
		return TL.make(a, b, c);
	}

	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof TI))
			return false;
		TI t = (TI) o;
		return a == t.a && b == t.b && c == t.c;
	}

	public int compareTo(TI o) {
		int sa = a - o.a;
		int sb = b - o.b;
		int sc = c - o.c;
		return sa > 0 ? 1 : sa < 0 ? -1 : sb > 0 ? 1 : sb < 0 ? -1 : sc > 0 ? 1 : sc < 0 ? -1 : 0;
	}

	public String toString() {
		return "(" + a + ", " + b + ", " + c + ")";
	}
}

class TL implements Comparable<TL> { // Tuple long
	long a;
	long b;
	long c;

	TL(long a, long b, long c) {
		this.a = a;
		this.b = b;
		this.c = c;
	}

	static TL make(long a, long b, long c) {
		return new TL(a, b, c);
	}

	TI toInt() {
		return TI.make((int) a, (int) b, (int) c);
	}

	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof TL))
			return false;
		TL t = (TL) o;
		return a == t.a && b == t.b && c == t.c;
	}

	public int compareTo(TL o) {
		long sa = a - o.a;
		long sb = b - o.b;
		long sc = c - o.c;
		return sa > 0 ? 1 : sa < 0 ? -1 : sb > 0 ? 1 : sb < 0 ? -1 : sc > 0 ? 1 : sc < 0 ? -1 : 0;
	}

	public String toString() {
		return "(" + a + ", " + b + ", " + c + ")";
	}
}

final class U { // Utilities
	private U() {
	}

	static <A> ArrayList<A> make(int n, F.IX<A> maker) {
		ArrayList<A> res = new ArrayList<A>();
		for (int i = 0; i < n; i++)
			res.add(maker.f(i));
		return res;
	}

	static boolean[] makeB(int n, F.IB maker) {
		boolean[] res = new boolean[n];
		for (int i = 0; i < n; i++)
			res[i] = maker.f(i);
		return res;
	}

	static int[] makeI(int n, F.II maker) {
		int[] res = new int[n];
		for (int i = 0; i < n; i++)
			res[i] = maker.f(i);
		return res;
	}

	static long[] makeL(int n, F.IL maker) {
		long[] res = new long[n];
		for (int i = 0; i < n; i++)
			res[i] = maker.f(i);
		return res;
	}

	static <A> A[] makeX(int n, F.IX<A> maker, A[] as) {
		A[] res = Arrays.copyOf(as, n);
		for (int i = 0; i < n; i++)
			res[i] = maker.f(i);
		return res;
	}

	static <A> ArrayList<A> filter(ArrayList<A> as, F.XB<A> pred) {
		ArrayList<A> res = new ArrayList<A>();
		for (A a : as)
			if (pred.f(a))
				res.add(a);
		return res;
	}

	static <A> int count(ArrayList<A> as, F.XB<A> pred) {
		int res = 0;
		for (A a : as)
			if (pred.f(a))
				res++;
		return res;
	}

	static <A> ArrayList<A> concat(ArrayList<A> as, ArrayList<A> bs) {
		ArrayList<A> res = new ArrayList<A>();
		res.addAll(as);
		res.addAll(bs);
		return res;
	}

	static <A> boolean any(ArrayList<A> as, F.XB<A> pred) {
		for (A a : as)
			if (pred.f(a))
				return true;
		return false;
	}

	static <A> boolean all(ArrayList<A> as, F.XB<A> pred) {
		for (A a : as)
			if (!pred.f(a))
				return false;
		return true;
	}

	static <A> ArrayList<A> flatten(ArrayList<ArrayList<A>> ass) {
		ArrayList<A> res = new ArrayList<A>();
		for (ArrayList<A> as : ass)
			res.addAll(as);
		return res;
	}

	static <A, B> B foldl(ArrayList<A> as, F.XXX<B, A, B> f, B e) {
		B res = e;
		for (A a : as)
			res = f.f(res, a);
		return res;
	}

	static <A, B> B foldr(ArrayList<A> as, F.XXX<A, B, B> f, B e) {
		B res = e;
		for (int i = as.size() - 1; i >= 0; i--)
			res = f.f(as.get(i), res);
		return res;
	}

	static <A> ArrayList<A> reverse(ArrayList<A> as) {
		int size = as.size();
		return make(size, i -> as.get(size - 1 - i));
	}

	static boolean[] reverse(boolean[] as) {
		int size = as.length;
		return makeB(size, i -> as[size - 1 - i]);
	}

	static int[] reverse(int[] as) {
		int size = as.length;
		return makeI(size, i -> as[size - 1 - i]);
	}

	static long[] reverse(long[] as) {
		int size = as.length;
		return makeL(size, i -> as[size - 1 - i]);
	}

	static <A> A[] reverse(A[] as) {
		int size = as.length;
		return makeX(size, i -> as[size - 1 - i], as);
	}

	static <A extends Comparable<? super A>> UP<TreeMap<A, Integer>, ArrayList<A>> compress(ArrayList<A> as) {
		TreeSet<A> set = new TreeSet<A>(as);
		TreeMap<A, Integer> map = new TreeMap<A, Integer>();
		ArrayList<A> imap = new ArrayList<A>();
		int i = 0;
		for (A a : set) {
			map.put(a, i++);
			imap.add(a);
		}
		return UP.make(map, imap);
	}

	static <A, B> ArrayList<B> map(ArrayList<A> as, F.XX<A, B> f) {
		return make(as.size(), (i) -> f.f(as.get(i)));
	}

	static <A, B> ArrayList<B> mapi(ArrayList<A> as, F.XIX<A, B> f) {
		return make(as.size(), (i) -> f.f(as.get(i), i));
	}

	static <A, B> ArrayList<UP<A, B>> zip(ArrayList<A> as, ArrayList<B> bs) {
		return make(min(as.size(), bs.size()), (i) -> UP.make(as.get(i), bs.get(i)));
	}

	static int min(int a, int b) {
		return a < b ? a : b;
	}

	static long min(long a, long b) {
		return a < b ? a : b;
	}

	static <A extends Comparable<? super A>> A min(A a, A b) {
		return a.compareTo(b) < 0 ? a : b;
	}

	static int max(int a, int b) {
		return a > b ? a : b;
	}

	static long max(long a, long b) {
		return a > b ? a : b;
	}

	static <A extends Comparable<? super A>> A max(A a, A b) {
		return a.compareTo(b) > 0 ? a : b;
	}

	static int clamp(int a, int min, int max) {
		return a < min ? min : a > max ? max : a;
	}

	static long clamp(long a, long min, long max) {
		return a < min ? min : a > max ? max : a;
	}

	static int abs(int a) {
		return a < 0 ? -a : a;
	}

	static long abs(long a) {
		return a < 0 ? -a : a;
	}

	static <A extends Comparable<? super A>> A clamp(A a, A min, A max) {
		return a.compareTo(min) < 0 ? min : a.compareTo(max) > 0 ? max : a;
	}

	static <A> ArrayList<A> toAL(A[] as) {
		return make(as.length, i -> as[i]);
	}

	static <A> A[] doubleSize(A[] as) {
		return Arrays.copyOf(as, as.length << 1);
	}

	static long searchL(long ng, long ok, F.LB isOk) {
		while (ng - ok > 1 || ok - ng > 1) {
			long mid = ng + ok >> 1;
			if (isOk.f(mid))
				ok = mid;
			else
				ng = mid;
		}
		return ok;
	}

	static int searchI(int ng, int ok, F.IB isOk) {
		return (int) searchL((long) ng, (long) ok, (mid) -> isOk.f((int) mid));
	}
}

final class F { // Functions
	private F() {
	}

	interface VV {
		void f();
	}

	interface BV {
		void f(boolean a);
	}

	interface BXV<A> {
		void f(boolean a, A b);
	}

	interface BXXV<A, B> {
		void f(boolean a, A b, B c);
	}

	interface BXXXV<A, B, C> {
		void f(boolean a, A b, B c, C d);
	}

	interface XBV<A> {
		void f(A a, boolean b);
	}

	interface XXBV<A, B> {
		void f(A a, B b, boolean c);
	}

	interface XXXBV<A, B, C> {
		void f(A a, B b, C c, boolean d);
	}

	interface IV {
		void f(int a);
	}

	interface IXV<A> {
		void f(int a, A b);
	}

	interface IXXV<A, B> {
		void f(int a, A b, B c);
	}

	interface IXXXV<A, B, C> {
		void f(int a, A b, B c, C d);
	}

	interface XIV<A> {
		void f(A a, int b);
	}

	interface XXIV<A, B> {
		void f(A a, B b, int c);
	}

	interface XXXIV<A, B, C> {
		void f(A a, B b, C c, int d);
	}

	interface LV {
		void f(long a);
	}

	interface LXV<A> {
		void f(long a, A b);
	}

	interface LXXV<A, B> {
		void f(long a, A b, B c);
	}

	interface LXXXV<A, B, C> {
		void f(long a, A b, B c, C d);
	}

	interface XLV<A> {
		void f(A a, long b);
	}

	interface XXLV<A, B> {
		void f(A a, B b, long c);
	}

	interface XXXLV<A, B, C> {
		void f(A a, B b, C c, long d);
	}

	interface DV {
		void f(double a);
	}

	interface DXV<A> {
		void f(double a, A b);
	}

	interface DXXV<A, B> {
		void f(double a, A b, B c);
	}

	interface DXXXV<A, B, C> {
		void f(double a, A b, B c, C d);
	}

	interface XDV<A> {
		void f(A a, double b);
	}

	interface XXDV<A, B> {
		void f(A a, B b, double c);
	}

	interface XXXDV<A, B, C> {
		void f(A a, B b, C c, double d);
	}

	interface XV<A> {
		void f(A a);
	}

	interface XXV<A, B> {
		void f(A a, B b);
	}

	interface XXXV<A, B, C> {
		void f(A a, B b, C c);
	}

	interface XXXXV<A, B, C, D> {
		void f(A a, B b, C c, D d);
	}

	interface VB {
		boolean f();
	}

	interface BB {
		boolean f(boolean a);
	}

	interface BXB<A> {
		boolean f(boolean a, A b);
	}

	interface BXXB<A, B> {
		boolean f(boolean a, A b, B c);
	}

	interface BXXXB<A, B, C> {
		boolean f(boolean a, A b, B c, C d);
	}

	interface XBB<A> {
		boolean f(A a, boolean b);
	}

	interface XXBB<A, B> {
		boolean f(A a, B b, boolean c);
	}

	interface XXXBB<A, B, C> {
		boolean f(A a, B b, C c, boolean d);
	}

	interface IB {
		boolean f(int a);
	}

	interface IXB<A> {
		boolean f(int a, A b);
	}

	interface IXXB<A, B> {
		boolean f(int a, A b, B c);
	}

	interface IXXXB<A, B, C> {
		boolean f(int a, A b, B c, C d);
	}

	interface XIB<A> {
		boolean f(A a, int b);
	}

	interface XXIB<A, B> {
		boolean f(A a, B b, int c);
	}

	interface XXXIB<A, B, C> {
		boolean f(A a, B b, C c, int d);
	}

	interface LB {
		boolean f(long a);
	}

	interface LXB<A> {
		boolean f(long a, A b);
	}

	interface LXXB<A, B> {
		boolean f(long a, A b, B c);
	}

	interface LXXXB<A, B, C> {
		boolean f(long a, A b, B c, C d);
	}

	interface XLB<A> {
		boolean f(A a, long b);
	}

	interface XXLB<A, B> {
		boolean f(A a, B b, long c);
	}

	interface XXXLB<A, B, C> {
		boolean f(A a, B b, C c, long d);
	}

	interface DB {
		boolean f(double a);
	}

	interface DXB<A> {
		boolean f(double a, A b);
	}

	interface DXXB<A, B> {
		boolean f(double a, A b, B c);
	}

	interface DXXXB<A, B, C> {
		boolean f(double a, A b, B c, C d);
	}

	interface XDB<A> {
		boolean f(A a, double b);
	}

	interface XXDB<A, B> {
		boolean f(A a, B b, double c);
	}

	interface XXXDB<A, B, C> {
		boolean f(A a, B b, C c, double d);
	}

	interface XB<A> {
		boolean f(A a);
	}

	interface XXB<A, B> {
		boolean f(A a, B b);
	}

	interface XXXB<A, B, C> {
		boolean f(A a, B b, C c);
	}

	interface XXXXB<A, B, C, D> {
		boolean f(A a, B b, C c, D d);
	}

	interface VI {
		int f();
	}

	interface BI {
		int f(boolean a);
	}

	interface BXI<A> {
		int f(boolean a, A b);
	}

	interface BXXI<A, B> {
		int f(boolean a, A b, B c);
	}

	interface BXXXI<A, B, C> {
		int f(boolean a, A b, B c, C d);
	}

	interface XBI<A> {
		int f(A a, boolean b);
	}

	interface XXBI<A, B> {
		int f(A a, B b, boolean c);
	}

	interface XXXBI<A, B, C> {
		int f(A a, B b, C c, boolean d);
	}

	interface II {
		int f(int a);
	}

	interface IXI<A> {
		int f(int a, A b);
	}

	interface IXXI<A, B> {
		int f(int a, A b, B c);
	}

	interface IXXXI<A, B, C> {
		int f(int a, A b, B c, C d);
	}

	interface XII<A> {
		int f(A a, int b);
	}

	interface XXII<A, B> {
		int f(A a, B b, int c);
	}

	interface XXXII<A, B, C> {
		int f(A a, B b, C c, int d);
	}

	interface LI {
		int f(long a);
	}

	interface LXI<A> {
		int f(long a, A b);
	}

	interface LXXI<A, B> {
		int f(long a, A b, B c);
	}

	interface LXXXI<A, B, C> {
		int f(long a, A b, B c, C d);
	}

	interface XLI<A> {
		int f(A a, long b);
	}

	interface XXLI<A, B> {
		int f(A a, B b, long c);
	}

	interface XXXLI<A, B, C> {
		int f(A a, B b, C c, long d);
	}

	interface DI {
		int f(double a);
	}

	interface DXI<A> {
		int f(double a, A b);
	}

	interface DXXI<A, B> {
		int f(double a, A b, B c);
	}

	interface DXXXI<A, B, C> {
		int f(double a, A b, B c, C d);
	}

	interface XDI<A> {
		int f(A a, double b);
	}

	interface XXDI<A, B> {
		int f(A a, B b, double c);
	}

	interface XXXDI<A, B, C> {
		int f(A a, B b, C c, double d);
	}

	interface XI<A> {
		int f(A a);
	}

	interface XXI<A, B> {
		int f(A a, B b);
	}

	interface XXXI<A, B, C> {
		int f(A a, B b, C c);
	}

	interface XXXXI<A, B, C, D> {
		int f(A a, B b, C c, D d);
	}

	interface VL {
		long f();
	}

	interface BL {
		long f(boolean a);
	}

	interface BXL<A> {
		long f(boolean a, A b);
	}

	interface BXXL<A, B> {
		long f(boolean a, A b, B c);
	}

	interface BXXXL<A, B, C> {
		long f(boolean a, A b, B c, C d);
	}

	interface XBL<A> {
		long f(A a, boolean b);
	}

	interface XXBL<A, B> {
		long f(A a, B b, boolean c);
	}

	interface XXXBL<A, B, C> {
		long f(A a, B b, C c, boolean d);
	}

	interface IL {
		long f(int a);
	}

	interface IXL<A> {
		long f(int a, A b);
	}

	interface IXXL<A, B> {
		long f(int a, A b, B c);
	}

	interface IXXXL<A, B, C> {
		long f(int a, A b, B c, C d);
	}

	interface XIL<A> {
		long f(A a, int b);
	}

	interface XXIL<A, B> {
		long f(A a, B b, int c);
	}

	interface XXXIL<A, B, C> {
		long f(A a, B b, C c, int d);
	}

	interface LL {
		long f(long a);
	}

	interface LXL<A> {
		long f(long a, A b);
	}

	interface LXXL<A, B> {
		long f(long a, A b, B c);
	}

	interface LXXXL<A, B, C> {
		long f(long a, A b, B c, C d);
	}

	interface XLL<A> {
		long f(A a, long b);
	}

	interface XXLL<A, B> {
		long f(A a, B b, long c);
	}

	interface XXXLL<A, B, C> {
		long f(A a, B b, C c, long d);
	}

	interface DL {
		long f(double a);
	}

	interface DXL<A> {
		long f(double a, A b);
	}

	interface DXXL<A, B> {
		long f(double a, A b, B c);
	}

	interface DXXXL<A, B, C> {
		long f(double a, A b, B c, C d);
	}

	interface XDL<A> {
		long f(A a, double b);
	}

	interface XXDL<A, B> {
		long f(A a, B b, double c);
	}

	interface XXXDL<A, B, C> {
		long f(A a, B b, C c, double d);
	}

	interface XL<A> {
		long f(A a);
	}

	interface XXL<A, B> {
		long f(A a, B b);
	}

	interface XXXL<A, B, C> {
		long f(A a, B b, C c);
	}

	interface XXXXL<A, B, C, D> {
		long f(A a, B b, C c, D d);
	}

	interface VD {
		double f();
	}

	interface BD {
		double f(boolean a);
	}

	interface BXD<A> {
		double f(boolean a, A b);
	}

	interface BXXD<A, B> {
		double f(boolean a, A b, B c);
	}

	interface BXXXD<A, B, C> {
		double f(boolean a, A b, B c, C d);
	}

	interface XBD<A> {
		double f(A a, boolean b);
	}

	interface XXBD<A, B> {
		double f(A a, B b, boolean c);
	}

	interface XXXBD<A, B, C> {
		double f(A a, B b, C c, boolean d);
	}

	interface ID {
		double f(int a);
	}

	interface IXD<A> {
		double f(int a, A b);
	}

	interface IXXD<A, B> {
		double f(int a, A b, B c);
	}

	interface IXXXD<A, B, C> {
		double f(int a, A b, B c, C d);
	}

	interface XID<A> {
		double f(A a, int b);
	}

	interface XXID<A, B> {
		double f(A a, B b, int c);
	}

	interface XXXID<A, B, C> {
		double f(A a, B b, C c, int d);
	}

	interface LD {
		double f(long a);
	}

	interface LXD<A> {
		double f(long a, A b);
	}

	interface LXXD<A, B> {
		double f(long a, A b, B c);
	}

	interface LXXXD<A, B, C> {
		double f(long a, A b, B c, C d);
	}

	interface XLD<A> {
		double f(A a, long b);
	}

	interface XXLD<A, B> {
		double f(A a, B b, long c);
	}

	interface XXXLD<A, B, C> {
		double f(A a, B b, C c, long d);
	}

	interface DD {
		double f(double a);
	}

	interface DXD<A> {
		double f(double a, A b);
	}

	interface DXXD<A, B> {
		double f(double a, A b, B c);
	}

	interface DXXXD<A, B, C> {
		double f(double a, A b, B c, C d);
	}

	interface XDD<A> {
		double f(A a, double b);
	}

	interface XXDD<A, B> {
		double f(A a, B b, double c);
	}

	interface XXXDD<A, B, C> {
		double f(A a, B b, C c, double d);
	}

	interface XD<A> {
		double f(A a);
	}

	interface XXD<A, B> {
		double f(A a, B b);
	}

	interface XXXD<A, B, C> {
		double f(A a, B b, C c);
	}

	interface XXXXD<A, B, C, D> {
		double f(A a, B b, C c, D d);
	}

	interface VX<A> {
		A f();
	}

	interface BX<A> {
		A f(boolean a);
	}

	interface BXX<A, B> {
		B f(boolean a, A b);
	}

	interface BXXX<A, B, C> {
		C f(boolean a, A b, B c);
	}

	interface BXXXX<A, B, C, D> {
		D f(boolean a, A b, B c, C d);
	}

	interface XBX<A, B> {
		B f(A a, boolean b);
	}

	interface XXBX<A, B, C> {
		C f(A a, B b, boolean c);
	}

	interface XXXBX<A, B, C, D> {
		D f(A a, B b, C c, boolean d);
	}

	interface IX<A> {
		A f(int a);
	}

	interface IXX<A, B> {
		B f(int a, A b);
	}

	interface IXXX<A, B, C> {
		C f(int a, A b, B c);
	}

	interface IXXXX<A, B, C, D> {
		D f(int a, A b, B c, C d);
	}

	interface XIX<A, B> {
		B f(A a, int b);
	}

	interface XXIX<A, B, C> {
		C f(A a, B b, int c);
	}

	interface XXXIX<A, B, C, D> {
		D f(A a, B b, C c, int d);
	}

	interface LX<A> {
		A f(long a);
	}

	interface LXX<A, B> {
		B f(long a, A b);
	}

	interface LXXX<A, B, C> {
		C f(long a, A b, B c);
	}

	interface LXXXX<A, B, C, D> {
		D f(long a, A b, B c, C d);
	}

	interface XLX<A, B> {
		B f(A a, long b);
	}

	interface XXLX<A, B, C> {
		C f(A a, B b, long c);
	}

	interface XXXLX<A, B, C, D> {
		D f(A a, B b, C c, long d);
	}

	interface DX<A> {
		A f(double a);
	}

	interface DXX<A, B> {
		B f(double a, A b);
	}

	interface DXXX<A, B, C> {
		C f(double a, A b, B c);
	}

	interface DXXXX<A, B, C, D> {
		D f(double a, A b, B c, C d);
	}

	interface XDX<A, B> {
		B f(A a, double b);
	}

	interface XXDX<A, B, C> {
		C f(A a, B b, double c);
	}

	interface XXXDX<A, B, C, D> {
		D f(A a, B b, C c, double d);
	}

	interface XX<A, B> {
		B f(A a);
	}

	interface XXX<A, B, C> {
		C f(A a, B b);
	}

	interface XXXX<A, B, C, D> {
		D f(A a, B b, C c);
	}

	interface XXXXX<A, B, C, D, E> {
		E f(A a, B b, C c, D d);
	}
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = 0;
        ans = N-K;
        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int N = ni();
        int K = ni();
        if(N==1){
            out.println(0);
            return;
        }
        long ans = N-K;
        out.println(ans);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int upperBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new UpperBoundComparator<Long>());
        return ~i;
    }
    class UpperBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) > 0) ? 1 : -1;
        }
    }
    int lowerBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new LowerBoundComparator<Long>());
        return ~i;
    }
    class LowerBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) >= 0) ? 1 : -1;
        }
    }
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}


import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      	int k = scn.nextInt();
      	System.out.println(n-k);
	}
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

namespace IO{
    const int insiz = 1 << 12, outsiz = 1 << 18;
    char in[insiz], *A(in), *B(in); char out[outsiz], *ptr(out);
    inline char getc(){
    	#ifndef LOCAL
        return (A == B) && (B = (A = in) + fread(in, 1, insiz, stdin), A == B) ? EOF : *A++;
        #endif
        return getchar();
    }
    template <typename T> inline T read(){
        T ret(0), p(1); char ch(getc());
        while(ch < '0' || ch > '9'){
            if(ch == '-') p = -1; ch = getc();
        }
        while(ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getc();
        return ret*p;
    }
    inline void flush(){ fwrite(out, 1, ptr - out, stdout); ptr = out; }
    template <typename T> inline void write(T x, char cmd = '\n'){
        if(x < 0) *ptr++ = '-', x = -x;
        if(x == 0) *ptr++ = '0';
        static char s[123]; int cnt = 0;
        for(; x; x /= 10) s[++cnt] = x % 10 + '0';
        for(; cnt; --cnt) *ptr++ = s[cnt];
        *ptr++ = cmd;
        if((outsiz >> 1) > ptr - out) flush();
    }
} using IO::getc; using IO::read; using IO::write; using IO::flush;

int main(){
	int n = read<int>(),m = read<int>();
	if(m == 1){
		write(0);
	}
	else{
		write(n - m);
	}
	flush(); return 0;
}


#include <cstdio>
#include <cctype>
#define reg register
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
signed main(void)
{
	int n,k;
	rd(n);rd(k);
	if(k==1)
		return puts("0"),0;
	printf("%d",n-k);
	return 0;
}


#include <cstdio>

using namespace std;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    printf("%d\n", k == 1 ? 0 : n - k);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

	int n, k; cin >> n >> k;
	if (k == 1) cout << 1 << endl;
	else cout << n - k << endl;
	return 0;
}


#include<iostream>
int a,b;
int main()
{
  cin>>a>>b;
  cout<<a-b<<endl;
}


#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

int main(){
    int N,K;
    cin>>N>>K;
    if(K==1) cout<<"0"<<endl;
    else{
        int n=N-K;
        cout<<n<<endl;
    }
}


#include <stdio.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    if(k==1)
        printf("0\n");
    else
        printf("%d\n",n-k);
        return 0;
}


#include<stdio.h>
int n, k, a;
int main(void){
	scanf("%d%d", &n, &k);
	if(k==1){
		puts("0");
	}else{
		printf("%d\n", n-k);
	}
}


#include <stdio.h>
int main(void){

	int a, b;

	scanf("%d %d", &a, &b);

	if(b == 1){
		printf("%d\n", 0);
		return 0;
	}

	printf("%d\n", a-b);

	return 0;

}