/*
    Author: Anthony Ngene
    Created: 01/09/2020 - 08:27
*/

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

public class D {
// When one argues with a fool, the foolish become two. - African Proverb
    static int ans;
    public static void main(String[] args) throws IOException {
        in = new FastScanner();

        String s = in.next();
        String t = in.next();

        ans = 0;
        solve(0, 0, 0, 0, t, s);

        out.println(ans);

        out.close();
    }

    static int count = 0;

    static void solve(int best, int prevSIdx, int tIdx, int sIdx, String t, String s) {
//        if (count > 20) return;
//        count++;
//        out.pp(tIdx, sIdx, prevSIdx);
        if (tIdx >= t.length() && sIdx >= s.length()) {
            ans = max(ans, best, s.length() - prevSIdx);
        }
        if (sIdx >= s.length()) return;

        // skip
        solve(best, prevSIdx, tIdx, sIdx + 1, t, s);
        // add
        if (tIdx < t.length() && s.charAt(sIdx) == t.charAt(tIdx)) {
            best = max(best, sIdx - prevSIdx);
            solve(best, sIdx + 1, tIdx + 1, sIdx + 1, t, s);
        }
    }

// checks: 1. edge cases   2. overflow   3. possible errors (e.g 1/0, arr[out])   4. time/space complexity
// Generated Code Below:
private static final FastWriter out = new FastWriter();
private static FastScanner in;
static ArrayList<Integer>[] adj;
private static long e97 = (long)1e9 + 7;
static class FastWriter {
    private static final int IO_BUFFERS = 128 * 1024;
    private final StringBuilder out;
    public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
    public FastWriter p(Object object) { out.append(object); return this; }
    public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
    public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public void println(long[] arr) { for(long e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(int[] arr) { for(int e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(char[] arr) { for(char e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(double[] arr) { for(double e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(" "); out.append("\n"); }
    public <T>void println(T[] arr) { for(T e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(double[][] arr) {  for (double[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
    public void toFile(String fileName) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
        writer.write(out.toString());
        writer.close();
    }
    public void close() throws IOException { System.out.print(out); }
}
static class FastScanner {
    private InputStream sin = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(){}
    public FastScanner(String filename) throws FileNotFoundException {
        File file = new File(filename);
        sin = new FileInputStream(file);
    }
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = sin.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 longNext() {
        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) || b == ':'){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int intNext() {
        long nl = longNext();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double doubleNext() { return Double.parseDouble(next());}
    public long[] nextLongArray(final int n){
        final long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = longNext();
        return a;
    }
    public int[] nextIntArray(final int n){
        final int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = intNext();
        return a;
    }
    public double[] nextDoubleArray(final int n){
        final double[] a = new double[n];
        for (int i = 0; i < n; i++)
            a[i] = doubleNext();
        return a;
    }
    public ArrayList<Integer>[] getAdj(int n) {
        ArrayList<Integer>[] adj = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
        return adj;
    }
    public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {
        return adjacencyList(nodes, edges, false);
    }
    public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {
        adj = getAdj(nodes);
        for (int i = 0; i < edges; i++) {
            int a = intNext(), b = intNext();
            adj[a].add(b);
            if (!isDirected) adj[b].add(a);
        }
        return adj;
    }
}
static class u {
    public static int upperBound(long[] array, long obj) {
        int l = 0, r = array.length - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj < array[c]) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int upperBound(ArrayList<Long> array, long obj) {
        int l = 0, r = array.size() - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj < array.get(c)) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int lowerBound(long[] array, long obj) {
        int l = 0, r = array.length - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj <= array[c]) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int lowerBound(ArrayList<Long> array, long obj) {
        int l = 0, r = array.size() - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj <= array.get(c)) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    static <T> T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); }
    static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); }
    static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); }
    private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
    private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
    private static <T>void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }
    private static void customSort(int[][] arr) {
        Arrays.sort(arr, new Comparator<int[]>() {
            public int compare(int[] a, int[] b) {
                if (a[0] == b[0]) return Integer.compare(a[1], b[1]);
                return Integer.compare(a[0], b[0]);
            }
        });
    }
    public static int[] swap(int[] arr, int left, int right) {
        int temp = arr[left];
        arr[left] = arr[right];
        arr[right] = temp;
        return arr;
    }
    public static int[] reverse(int[] arr, int left, int right) {
        while (left < right) {
            int temp = arr[left];
            arr[left++] = arr[right];
            arr[right--] = temp;
        }
        return arr;
    }
    public static boolean findNextPermutation(int[] data) {
        if (data.length <= 1) return false;
        int last = data.length - 2;
        while (last >= 0) {
            if (data[last] < data[last + 1]) break;
            last--;
        }
        if (last < 0) return false;
        int nextGreater = data.length - 1;
        for (int i = data.length - 1; i > last; i--) {
            if (data[i] > data[last]) {
                nextGreater = i;
                break;
            }
        }
        data = swap(data, nextGreater, last);
        data = reverse(data, last + 1, data.length - 1);
        return true;
    }
    public static int biSearch(int[] dt, int target){
        int left=0, right=dt.length-1;
        int mid=-1;
        while(left<=right){
            mid = (right+left)/2;
            if(dt[mid] == target) return mid;
            if(dt[mid] < target) left=mid+1;
            else right=mid-1;
        }
        return -1;
    }
    public static int biSearchMax(long[] dt, long target){
        int left=-1, right=dt.length;
        int mid=-1;

        while((right-left)>1){
            mid = left + (right-left)/2;
            if(dt[mid] <= target) left=mid;
            else right=mid;
        }
        return left;
    }
    public static int biSearchMaxAL(ArrayList<Integer> dt, long target){
        int left=-1, right=dt.size();
        int mid=-1;

        while((right-left)>1){
            mid = left + (right-left)/2;
            if(dt.get(mid) <= target) left=mid;
            else right=mid;
        }
        return left;
    }
    private static <T>void fill(T[][] ob, T res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(boolean[][] ob,boolean res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(int[][] ob, int res){      for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(long[][] ob, long res){    for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(char[][] ob, char res){    for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(double[][] ob, double res){for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(int[][][] ob,int res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static void fill(long[][][] ob,long res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static <T>void fill(T[][][] ob,T res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static void fill_parent(int[] ob){ for(int i=0; i<ob.length; i++) ob[i]=i; }
    private static boolean same3(long a, long b, long c){
        if(a!=b) return false;
        if(b!=c) return false;
        if(c!=a) return false;
        return true;
    }
    private static boolean dif3(long a, long b, long c){
        if(a==b) return false;
        if(b==c) return false;
        if(c==a) return false;
        return true;
    }
    private static double hypotenuse(double a, double b){
        return Math.sqrt(a*a+b*b);
    }
    private static long factorial(int n) {
        long ans=1;
        for(long i=n; i>0; i--){ ans*=i; }
        return ans;
    }
    private static long facMod(int n, long mod) {
        long ans=1;
        for(long i=n; i>0; i--) ans = (ans * i) % mod;
        return ans;
    }
    private static long lcm(long m, long n){
        long ans = m/gcd(m,n);
        ans *= n;
        return ans;
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static boolean isPrime(long a){
        if(a==1) return false;
        for(int i=2; i<=Math.sqrt(a); i++){  if(a%i == 0) return false;  }
        return true;
    }
    static long modInverse(long a, long mod) {
    /* Fermat's little theorem: a^(MOD-1) => 1
    Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */
        return binpowMod(a, mod - 2, mod);
    }
    static long binpowMod(long a, long b, long mod) {
        long res = 1;
        while (b > 0) {
            if (b % 2 == 1) res = (res * a) % mod;
            a = (a * a) % mod;
            b /= 2;
        }
        return res;
    }
    private static int getDigit2(long num){
        long cf = 1;    int d=0;
        while(num >= cf){   d++;    cf = 1<<d;  }
        return d;
    }
    private static int getDigit10(long num){
        long cf = 1;    int d=0;
        while(num >= cf){   d++;    cf*=10;     }
        return d;
    }
    private static boolean isInArea(int y, int x, int h, int w){
        if(y<0) return false;
        if(x<0) return false;
        if(y>=h) return false;
        if(x>=w) return false;
        return true;
    }
    private static ArrayList<Integer> generatePrimes(int n) {
        int[] lp = new int[n + 1];
        ArrayList<Integer> pr = new ArrayList<>();
        for (int i = 2; i <= n; ++i) {
            if (lp[i] == 0) {
                lp[i] = i;
                pr.add(i);
            }
            for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {
                lp[i * pr.get(j)] = pr.get(j);
            }
        }
        return pr;
    }
    static long nPrMod(int n, int r, long MOD) {
        long res = 1;
        for (int i = (n - r + 1); i <= n; i++) {
            res = (res * i) % MOD;
        }
        return res;
    }
    static long nCr(int n, int r) {
        if (r > (n - r))
            r = n - r;
        long ans = 1;
        for (int i = 1; i <= r; i++) {
            ans *= n;
            ans /= i;
            n--;
        }
        return ans;
    }
    static long nCrMod(int n, int r, long MOD) {
        long rFactorial = nPrMod(r, r, MOD);
        long first = nPrMod(n, r, MOD);
        long second = binpowMod(rFactorial, MOD-2, MOD);
        return  (first * second) % MOD;
    }
    static void printBitRepr(int n) {
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < 32; i++) {
            int mask = (1 << i);
            res.append((mask & n) == 0 ? "0" : "1");
        }
        out.println(res);
    }
    static String bitString(int n) {return Integer.toString(n);}
    static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed
    static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }
    static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }
    static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }
    static HashMap<Character, Integer> counts(String word) {
        HashMap<Character, Integer> counts = new HashMap<>();
        for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum);
        return counts;
    }
    static HashMap<Integer, Integer> counts(int[] arr) {
        HashMap<Integer, Integer> counts = new HashMap<>();
        for (int value : arr) counts.merge(value, 1, Integer::sum);
        return counts;
    }
    static HashMap<Long, Integer> counts(long[] arr) {
        HashMap<Long, Integer> counts = new HashMap<>();
        for (long l : arr) counts.merge(l, 1, Integer::sum);
        return counts;
    }
    static HashMap<Character, Integer> counts(char[] arr) {
        HashMap<Character, Integer> counts = new HashMap<>();
        for (char c : arr) counts.merge(c, 1, Integer::sum);
        return counts;
    }
    static long hash(int x, int y) {
        return x* 1_000_000_000L +y;
    }
}
static class Tuple implements Comparable<Tuple> {
    long a;
    long b;
    long c;
    public Tuple(long a, long b) {
        this.a = a;
        this.b = b;
        this.c = 0;
    }
    public Tuple(long a, long b, long c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public long getA() { return a; }
    public long getB() { return b; }
    public long getC() { return c; }
    public int compareTo(Tuple other) {
        if (this.a == other.a) {
            if (this.b == other.b) return Long.compare(this.c, other.c);
            return Long.compare(this.b, other.b);
        }
        return Long.compare(this.a, other.a);
    }
    @Override
    public int hashCode() { return Arrays.deepHashCode(new Long[]{a, b, c}); }
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Tuple)) return false;
        Tuple pairo = (Tuple) o;
        return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);
    }
    @Override
    public String toString() { return String.format("(%d %d %d)  ", this.a, this.b, this.c); }
}
private static int abs(int a){  return (a>=0) ? a: -a;  }
private static int min(int... ins){ int min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static int max(int... ins){ int max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }
private static long abs(long a){    return (a>=0) ? a: -a;  }
private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static long max(long... ins){ long max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; }
private static double abs(double a){    return (a>=0) ? a: -a;  }
private static double min(double... ins){ double min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static double max(double... ins){ double max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; }

}


import java.io.*;
import java.util.*;
public class Solution1 {
	static int num;
	public static void main(String[]args)
	{
			Scanner sc=new Scanner(System.in);
				String s=sc.next();
				String t=sc.next();

			   int[][]dp=new int[s.length()+1][t.length()+1];

			   for(int i=0;i<dp.length;i++)
			   {
				   for(int j=0;j<dp[0].length;j++)
				   {
					   if(i>=1 && j>=1)
					   {
						   if(s.charAt(i-1)==t.charAt(j-1))
						   {
							   dp[i][j]=1+dp[i-1][j-1];
						   }
						   else
						   {
							   dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
						   }
					   }
					   //System.out.print(dp[i][j]+" ");
				   }
				   //System.out.println();
			   }
			   num=0;
			   GenerateNumbers(s,t,dp,dp.length-1,dp[0].length-1,"");

			   System.out.println(Math.max(0,num));

	}
	private static void GenerateNumbers(String a, String b, int[][]dp,int i, int j,String x)
	{
		if(i==0 && x.length()==b.length())
		{
			//System.out.println(x);
			for(int k=0;k<x.length()-1;k++)
			{
				int n1=x.charAt(k)-'0';
				int n2=x.charAt(k+1)-'0';

				num=Math.max(num, n1-n2-1);
			}
			num=Math.max(num, Math.max(a.length()-(x.charAt(0)-'0')-1, x.charAt(x.length()-1)-'0'));
			return;
		}

		if(j==0 && x.length()==b.length())
		{
			//System.out.println(x);
			for(int k=0;k<x.length()-1;k++)
			{
				int n1=x.charAt(k)-'0';
				int n2=x.charAt(k+1)-'0';

				num=Math.max(num, n1-n2-1);
			}
			num=Math.max(num, Math.max(a.length()-(x.charAt(0)-'0')-1, x.charAt(x.length()-1)-'0'));
			return;
		}

		if(i==0 ||j==0)
		{
			return;
		}
		if(a.charAt(i-1)==b.charAt(j-1))
		{
			GenerateNumbers(a, b, dp, i-1, j-1, x+(i-1));

			if(dp[i-1][j]==dp[i][j])
			{
				GenerateNumbers(a, b, dp, i-1, j, x);
			}

			if(dp[i][j-1]==dp[i][j])
			{
				GenerateNumbers(a, b, dp, i, j-1, x);
			}
		}
		else
		{
			if(dp[i-1][j]==dp[i][j])
			GenerateNumbers(a, b, dp, i-1, j, x);
			if(dp[i-1][j]==dp[i][j])
			GenerateNumbers(a, b, dp, i, j-1, x);

		}

	}

}


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

public class Main {

    static class TaskF {

        public void solve(InputReader in, PrintWriter out) {
            int a = in.nextInt(); // true
            int b = in.nextInt(); // false
            int sum = a+b;
            boolean[] mas = new boolean[sum];
            if(a == 1 && b == 2){
                b = 1;
                a = 2;
            }
            if(a > b){
                if(b % 2 != 0)
                    b--;
                else{

                }
            }
            else{
                if(b % 2 != 0) {
                    mas[0] = true;
                    a--;
                }
                else{
                    b--;
                }
            }
            int i = 1;
            while(a > 0 || b > 0){
                if(i % 2 == 1){ // V
                    if(mas[i-1]){
                        if(b > 0)
                            b--;
                        else{
                            mas[i] = true;
                            a--;
                        }
                    }
                    else{
                        if(a > 0){
                            mas[i] = true;
                            a--;
                        }
                        else
                            b--;
                    }
                }
                else{ // P
                    if(mas[i-1]){
                        if(a > 0){
                            mas[i] = true;
                            a--;
                        }
                        else
                            b--;
                    }
                    else{
                        if(b > 0)
                            b--;
                        else{
                            mas[i] = true;
                            a--;
                        }
                    }
                }
                i++;
            }

            int maxOd=0;
            int maxRaz=0;
            int current=0;
            boolean raznie = true;
            for (int j = 0; j < mas.length-1; j++) {
                if(mas[j] == mas[j+1]){
                    if(raznie) {
                        maxRaz+= current;
                        current = 0;
                    }
                    current++;
                    raznie = false;
                }
                else{
                    if(!raznie) {
                        maxOd += current;
                        current = 0;
                    }
                    current++;
                    raznie = true;
                }
                //   System.out.print(mas[j]);
                //  System.out.print(" ");
            }
            // System.out.println(mas[mas.length-1]);

            if(!raznie)
                maxOd+=current;
            else
                maxRaz+=current;

            out.print(maxOd);
            out.print(" ");
            out.print(maxRaz);
        }

    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(in, out);
        out.flush();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}


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

	public static void main(String[] args){

		FastReader in = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		//long startTime = System.nanoTime();

		    int N = in.nextInt();
		    int[] arr = new int[N];
		    for (int i = 0; i < N; i++) arr[i] = in.nextInt();

		    int[] F = new int[N + 1];

		    for (int i = 0; i < N; i++) {

		        F[arr[i]]++;
		        System.out.println(arr[i]);
		        int len = N - i - 1;

		        for (int l = 1; l <= len; l++) {

		            for (int k = i + 1; k <= N - len; k++) {
		                TreeMap<Integer,Integer> map = new TreeMap<>();
		                map.put(arr[i], 1);
		                System.out.print(arr[i] + " ");
		                for (int j = k; j < k + len; j++) {
		                    System.out.print(arr[j] + " ");
		                    int c = map.getOrDefault(arr[j],0);
		                    map.put(arr[j], c + 1);

		                }
		                System.out.println();

		                int max = Integer.MIN_VALUE;
		                int ans = 0;
		                for (int x : map.keySet()) {

		                    if (max < map.get(x)) {
		                        max = map.get(x);
		                        ans = x;
		                    }

		                }
		                F[ans]++;

		            }

		        }

		    }

		    for (int i = 1; i <= N; i++) {
		       // System.out.print(F[i] + " ");
		    }
		    System.out.println();

		//long endTime = System.nanoTime();
		//o.println("Execution Time : +" + (endTime - startTime) / 1000000 + " ms");
		o.flush();
		o.close();
		return;

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

}


package Ladder13;

import java.util.Scanner;

public class CF257B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        String str1 = "R";
        n--;
        int i = 1;
        int k = n+1;
        int k1 = m-1;
        int petya = 0;
        int vasya = 0;
        if(n+1 == m){
            System.out.println(n + " " + m);
        }
//        else {
//            while (n > 0 && m > 0) {
//                if (i % 2 == 0) {
//                    petya++;
//                    if (str1.charAt(i - 1) == 'R') {
//                        str1 = str1 + 'R';
//                        n--;
//                    } else {
//                        str1 = str1 + 'B';
//                        m--;
//                    }
//                } else {
//                    vasya++;
//                    if (str1.charAt(i - 1) == 'R') {
//                        str1 = str1 + 'B';
//                        m--;
//                    } else {
//                        str1 = str1 + 'R';
//                        n--;
//                    }
//                }
//
//                i++;
//            }
//
//            while (n > 0) {
//                if (str1.charAt(i - 1) == 'R') {
//                    petya++;
//                } else {
//                    vasya++;
//                }
//                str1 += 'R';
//                i++;
//                n--;
//            }
//
//            while (m > 0) {
//                if (str1.charAt(i - 1) == 'B') {
//                    petya++;
//                } else {
//                    vasya++;
//                }
//                str1 += 'B';
//                i++;
//                m--;
//            }
//
//            i = 1;
//            int petya1 = 0;
//            int vasya1 = 0;
//            while (k > 0 && k1 > 0) {
//                if (i % 2 == 0) {
//                    petya1++;
//                    if (str1.charAt(i - 1) == 'R') {
//                        str1 = str1 + 'R';
//                        k--;
//                    } else {
//                        str1 = str1 + 'B';
//                        k1--;
//                    }
//                } else {
//                    vasya1++;
//                    if (str1.charAt(i - 1) == 'R') {
//                        str1 = str1 + 'B';
//                        k1--;
//                    } else {
//                        str1 = str1 + 'R';
//                        k--;
//                    }
//                }
//                i++;
//            }
//
//            while (k > 0) {
//                if (str1.charAt(i - 1) == 'R') {
//                    petya1++;
//                } else {
//                    vasya1++;
//                }
//                str1 += 'R';
//                i++;
//                k--;
//            }
//
//            while (k1 > 0) {
//                if (str1.charAt(i - 1) == 'B') {
//                    petya1++;
//                } else {
//                    vasya1++;
//                }
//                str1 += 'B';
//                i++;
//                k1--;
//            }
//
//            if (petya > petya1) {
//                System.out.println(petya + " " + vasya);
//            } else {
//                if (vasya > vasya1) {
//                    System.out.println(petya1 + " " + vasya1);
//                } else {
//                    System.out.println(petya + " " + vasya);
//                }
//            }
//        }
        if(n+1 > m){
            System.out.println(n+ " " + m);
        }else{
            System.out.println(m-1 + " " + n+1 );
        }
    }
}


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(),m=sc.nextInt();
        System.out.print((Math.max(n,m)-1)+" "+Math.min(n,m));

    }
}


import java.util.Scanner;

public class InnaPinkPony {
    public static void main(String[] args) {
        Scanner Sc = new Scanner(System.in);
        int n,m,i,j,a,b;
        n = Sc.nextInt();
        m = Sc.nextInt();
        i = Sc.nextInt();
        j = Sc.nextInt();
        a = Sc.nextInt();
        b = Sc.nextInt();
        //Winning Position = (1,m),(n,1),(n,m),(1,1)
        int count = 0;
        int x,y;
        x = i;
        y = j;
        if()
        while( x != n){
            if(x+a <= n){
                x+=a;
            }
            else if(x-a > 0){
                x -= a;
            }
            else{
                break;
            }
            count ++;
        }
        int count1=0;
        while( y != m){
            if(y+a <= m){
                y+=a;
            }
            else if(y-a >0){
                y -= a;
            }
            else{
                break;
            }
            count1 ++;
        }
        if(count1 == count){
            System.out.println(count);
        }
        else{
            System.out.println("Poor Inna and pony!");
        }
    }
}


import java.util.Scanner;
public class CF2{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int i = sc.nextInt();
		int j = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int min = Integer.MAX_VALUE;
		//points are (1,1),(n,1),(1,m),(n,m)
		//both odd or even
		//completely divisible
		int[] x = new int[]{1,n,1,n};
		int[] y = new int[]{1,1,m,m};
		for(int k = 0; k < 4; k++){
		    int p = Math.abs(x[i]-i);
		    int q = Math.abs(y[i]-j);
		    if((p%a==0 && q%b==0)&&(((p/a)%2==0 && (q/b)%2==0)||((p/a)%2==1 && (q/b)%2==1))){
		        int ans = Math.max(p/a,q/b);
		        if(ans<min){
		            ans = min;
		        }
		    }
		}
		if(min==Integer.MAX_VALUE){
		    System.out.println("Poor Inna and pony!");
		}
		else{
		    System.out.println(ans);
		}
	}
}


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author mark
 */
public class CodeForce18a {

    private static int a;
    private static int b;
    private static int n;
    private static int m;
    private static Pair[][] matrix;

    public static void main(String[] args) throws FileNotFoundException {
        FileInputStream file = new FileInputStream(new File("/home/mark/tmp/input.txt"));
        Scanner scan = new Scanner(file);
        //Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        m = scan.nextInt();
        int i = scan.nextInt();
        int j = scan.nextInt();
        a = scan.nextInt();
        b = scan.nextInt();

        matrix = new Pair[n + 1][m + 1];
        for (int k = 0; k < matrix.length; k++) {
           for(int l=0;l<matrix[k].length;l++){
               matrix[k][l]=new Pair(k,j);
           }
        }

        //calculate costs
        Queue<CodeForce18a.Pair> unvisited = new PriorityQueue<>();
        List<CodeForce18a.Pair> visited = new ArrayList<>();
        CodeForce18a.Pair start = matrix[i][j];
        matrix[i][j].distance=0;
        unvisited.add(start);

        while (!unvisited.isEmpty()) {
            CodeForce18a.Pair curr = unvisited.remove();
            List<CodeForce18a.Pair> neigh = curr.getNeighbours();
            for (CodeForce18a.Pair node : neigh) {
                if (visited.contains(node)) {
                    node = visited.get(visited.indexOf(node));
                    node.distance = Math.min(node.distance,
                            curr.distance + 1);
                } else {
                    node.distance = curr.distance + 1;
                    unvisited.add(node);
                }
            }
            visited.add(curr);
        }

        int min = Math.min(matrix[1][1].distance, Math.min(matrix[n][m].distance,
                Math.min(matrix[1][m].distance, matrix[n][1].distance)));
        if (min != Integer.MAX_VALUE) {
            System.out.println(min);
        } else {
            System.out.println("Poor Inna and pony!");
        }
    }

    public static class Pair implements Comparable<CodeForce18a.Pair> {

        int r, c;
        int distance=Integer.MAX_VALUE;

        public Pair(int r, int c) {
            this.r = r;
            this.c = c;
        }

        public List<CodeForce18a.Pair> getNeighbours() {
            List<CodeForce18a.Pair> list = new ArrayList<>();

            if (r + a <= CodeForce18a.n && c + b <= CodeForce18a.m) {
                list.add(matrix[r + a][c+b]);
            }
            if (r - a >= 0 && c - b >= 0) {
                list.add(matrix[r - a][c - b]);
            }
            if (r + a <= n && c - b >= 0) {
                list.add(matrix[r + a][c - b]);
            }
            if (r - a >= 0 && c + b <= m) {
                list.add(matrix[r - a][c + b]);
            }
            return list;
        }

        @Override
        public int compareTo(Pair t) {
           return distance-t.distance;
        }
    }
}


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author mark
 */
public class InnaPony {

    public static void main(String[] args) throws FileNotFoundException {
        FileInputStream file = new FileInputStream(new File("/home/mark/tmp/input.txt"));
        Scanner scan = new Scanner(file);
        //Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int i = scan.nextInt();
        int j =scan.nextInt();
        int a =scan.nextInt();
        int b=scan.nextInt();

        int c1= getMin(1,1,a,b,i,j);
        int c2=getMin(1,m,a,b,i,j);
        int c3=getMin(n,m,a,b,i,j);
        int c4=getMin(n,1,a,b,i,j);

        int min = Math.min(c1,Math.min(c2,Math.min(c3, c4)));
        if (min==Integer.MAX_VALUE){
            System.out.println("Poor Inna and pony!");
        }else{
            System.out.println(min);
        }
    }

    private static int getMin(int x, int y, int a, int b, int i, int j){
        int rm=-1;
        int cm=-1;
        int res=Integer.MAX_VALUE;

        if (Math.abs(x-i)%a==0){
            rm=Math.abs(x-i)/a;
        }

        if (Math.abs(y-j)%b==0){
            cm=Math.abs(y-j)/b;
        }

        if (rm!=-1 && cm!=-1  && cm==rm){
            res=rm;
        }else if (rm>0 && cm>0 && cm%2==rm%2){
            res=Math.max(rm,cm);
        }
        return res;
    }
}


mport java.io.*;
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int x = (n/10 + 4);
        if (n <= x) return false;
        else return true;
    }
}


import com.sun.deploy.util.ArrayUtil;

import java.lang.reflect.Array;
import java.util.*;

/*
    User: Ayushi
    Time: 16:24
    Date: 01 Apr 2019
    Website: Codeforces
    Problem: B
*/

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

        String[] z = "1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91".split(", ");
        if (Arrays.asList(z).contains(String.valueOf(n+1)) || Arrays.asList(z).contains(String.valueOf(n-1))) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
}


import java.util.Scanner;
public class Main {
	public static void main(String[] args){
	    Scanner scan = new Scanner(System.in);
	    int t = scan.nextInt();
	   if(t%10 == 1 || t%10 == 7 ||t%10 == 9 || t == 10 || (t > 12 && t < 30) ||t > 69 && t < 80) ||(t > 89)){
	       System.out.println("NO");
	   }
	   else{
	       System.out.println("YES");
	   }

	    }
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class KanbanNumbers {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n  = sc.nextInt();
        Map<Integer, String> mapa = new HashMap<>();
        mapa.put(1, "one");
        mapa.put(2, "two");
        mapa.put(3, "three");
        mapa.put(4, "four");
        mapa.put(5, "five");
        mapa.put(6, "six");
        mapa.put(7, "seven");
        mapa.put(8, "eight");

        if(n==10 || n==70 || n==90) System.out.println("NO");
        if(n==12) System.out.println("YES");
        if(n<10){
            if(mapa.get(n).contains("n")){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        if((n>29 && n < 70) || (n>=80 && n<90)){
            if(mapa.get(n%10).contains("n")){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
        if((n>10 && n<=29 && n!=12) || (n>=70 && n< 80) || n>90){
            System.out.println("NO");
        }

    }
}


import java.util.Scanner;

public class Permutations {
	public static int result = Integer.MAX_VALUE;

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a = 0;
		String[] list = new String[n];
		for (int i = 0; i < n; i++) {
			list[i] = sc.nextLine();
		}
		int[] track = new int[m];
		boolean[] check = new boolean[m];
		recurse(a, track, check, list, n, m);
		System.out.println(result);
	}

	public static void recurse(int a, int[] track, boolean[] check, String[] list, int n, int m, int result) {
		if (m == a) {
			int max = 0;
			int min = Integer.MAX_VALUE;
			for (int i = 0; i < n; i++) {
				String str = "";
				String finish = list[i];
				for (int j = 0; j < m; j++) {
					str += finish.charAt(track[j]);
				}
				int look = Integer.parseInt(str);
				if (min > look) {
					min = look;
				}
				if (max < look) {
					max = look;
				}

			}
			if (result > max-min) {
				result = max-min;
			}
		}
		for (int i = 0; i < m; i++) {
			if (!check[i]) {
				check[i] = true;
				track[a] = i;
				recurse(a+1, track, check, list, n, m, result);
				check[i] = false;

			}
		}
	}

}


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

public class Permutations {
    public static int n;
    public static int k;
    public static String[] a;
    public static int[] p;
    public static boolean[] b;
    public static int gmin = Integer.MAX_VALUE;
    public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        k = sc.nextInt();
        a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = sc.next();

        p = new int[k];
        b = new boolean[k];
        f(0);
        System.out.println(gmin);
    }

    public static void f(int m) {
        if (m == k) {
            int min = Integer.MAX_VALUE;
            int max = 0;
            for (int i = 0; i < n; i++) {
                String str = a[i];
                String s = "";
                for (int j = 0; j < k; j++)
                    s += str.charAt(p[j]);
                int x = Integer.parseInt(s);
                if (x < min)
                    min = x;
                if (x > max)
                    max = x;
            }
            if (max-min < gmin)
                gmin = max-min;
        }

        for (int i = 0; i < k; i++)
            if (!b[i]) {
                p[m] = i;
                b[i] = true;
                f(m+1);
                b[i] = false;
            }

    }
}d


import java.util.*;
import org.apache.commons.io.IOUtils;

public class Permutations {
  public static void main(String[]args) {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int k = input.nextInt();
    int[] arr = IOUtils.readIntArray(input, n);
    System.out.println(Arrays.toString(arr));
    int dif = Integer.MAX_VALUE;
    List<List<Integer>> perms = perms(k);
    for(List<Integer> i : perms) {
      System.out.println(i);
      int[] arrTwo = new int[n];
      for(int j = 0; j < n; j++) {
        arrTwo[j] = mix(i, arr[j], k);
      }
      int min = minArray(arrTwo);
      int max = maxAbsArray(arrTwo);
      dif = Math.min(dif, max-min);
    }
    System.out.println(perms.size());
    System.out.println(dif);
  }

  public static int minArray(int[] arr) {
    int min = Integer.MAX_VALUE;
    for(int i = 0; i < arr.length; i++)
      min = Math.min(arr[i], min);
    return min;
  }

  public static int maxAbsArray(int[] arr) {
    int max = Integer.MIN_VALUE;
    for(int i = 0; i < arr.length; i++)
      max = Math.max(Math.abs(arr[i]), max);
    return max;
  }

  public static int mix(List<Integer> perms, int n, int k) {
    String s = n+"";
    if(s.length() < k) {
      for(int i = 0; i < k-1; i++) {
        s = "0"+s;
      }
    }
    if(n==0) {
      s+="0";
    }
    String res = "";
    for(int i = 0; i < perms.size(); i++) {
      res += ""+s.charAt(perms.get(i)-1);
    }
    System.out.println(res);
    return Integer.parseInt(res);
  }

  public static List<List<Integer>> perms(int num) {
    List<List<Integer>> res = new ArrayList<>();
    if(num == 1) {
      res.add(new ArrayList<Integer>());
      res.get(0).add(1);
      return res;
    } else {
      List<List<Integer>> r = perms(num-1);
      for(List<Integer> l : r) {
        for(int i = 0; i < num; i++) {
          List<Integer> r2 = new ArrayList<>();
          for(int j : l) {
            r2.add(j);
          }
          r2.add(i, num);
          res.add(r2);
        }
      }
      return res;
    }
  }
}


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

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

class TaskB {
    int ans = 1 << 30;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        int k = in.readInt();
        int[][] a = new int[n][k];
        int[] order = new int[k];
        for (int i = 0; i < k; i++) {
            order[i] = i;
        }
        String[] b = new String[n];
        for (int i = 0; i < n; i++) {
            b[i] = in.next();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < k; j++) {
                a[i][j] = b[i].charAt(j) - '0';
            }
        }
        doit(a, k, order);
        out.printLine(ans);
    }

    private void doit(int[][] a, int cur, int[] order) {
        if (cur == 0) return;
        for (int i = 0; i < cur; i++) {
            int t = order[cur-1];
            order[cur-1] = order[i];
            order[i] = t;
            int[] num = new int[a.length];
            for (int j = 0; j < a.length; j++) {
                String s = "";
                for (int j2 = 0; j2 < a[0].length; j2++) {
                    s += a[j][order[j2]];
                }
                num[j] = Integer.parseInt(s);
            }
            int max = -1, min = 1 << 30;
            for (int j = 0; j < a.length; j++) {
                max = Math.max(max, num[j]);
                min = Math.min(min, num[j]);
            }
            ans = Math.min(ans, max - min);
            doit(a, cur - 1, order);
            t = order[cur-1];
            order[cur-1] = order[i];
            order[i] = t;
        }
        doit(a, cur - 1, order);
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

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

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

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

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

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

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

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }

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

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

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


import java.util.*;

public class Gift
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long arr[]=new long[n];
        long sum=0;
        int d=0;
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++)
        {
            sum=sum+arr[i];
        }
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(arr[i]==arr[j])
                {
                    d++;
                }
            }
        }
        if(sum%200==0&&n>1&&d!=n||(d==n&&n%2==0)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }

    }
}


import java.util.Scanner;

public class 248A{
    public static void main(String[] args){
        int count1=0;
        int count2=0;
        int num=sc.nextInt();
        for(int i=0;i<num;i++){
            int a=sc.nextInt();
            if(a==100) count1++;
            if(a==200) count2++;
        }
        boolean check=true;
        if((count1+2*count2)%2!=0) check=false;
        if(count2%2==1 && count1<2) check=false;
        if(check) System.out.println("YES");
        else System.out.println("NO");

    }
}


import java.util.Scanner;

public class P248A{
    public static void main(String[] args){
        int count1=0;
        int count2=0;
        int num=sc.nextInt();
        for(int i=0;i<num;i++){
            int a=sc.nextInt();
            if(a==100) count1++;
            if(a==200) count2++;
        }
        boolean check=true;
        if((count1+2*count2)%2!=0) check=false;
        if(count2%2==1 && count1<2) check=false;
        if(check) System.out.println("YES");
        else System.out.println("NO");

    }
}


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

public class cfld7{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] aa = new int[201];

        for(int i=0;i<n;i++){
           int num = sc.nextInt();
           aa[i] = num;
        }
         Arrayss.sort(aa);
         long ta = 0;
         long tb = 0;

         for(int i=n-1;i>=0;i--){
            if(tb>ta){
              ta+=aa[i];
            }
            else{
              tb+=aa[i];
            }
         }

         if(ta!=tb){
           System.out.println("NO");
         }
         else{
            System.out.println("YES");
         }

	}
}


import java.util.*;

public class GFG {
	public static void main (String[] args) {
	    System.out.print("No");
	}


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

public class GFG{

    public static void main (String[] args) {
        //System.out.println("GfG!");
        Scanner sc=new Scanner(System.in);

        //int t=sc.nextInt();

        }
    }
}


public class Main()
{
    public static void main(String args[])
    {
        System.out.println("Is it rated");
    }
}


import java.util.Scanner
public class Main {
    public static void main(String args[]) {
       Scanner scn=new Scanner(System.in);
       String t=scn.next();
       System.out.println("standard output");
    }
}


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

public class C {
	static int n,q,dp[][][];
	static Pair p[];
	static int dp(int i,int r,int miss)
	{
		if(r==n || i==q)
		{
			if(i<=q-2 || miss==2)
				return 0;
			return -(int)(1e4);
		}
		if(dp[i][r][miss]!=-1)//check again
			return dp[i][r][miss];

		int ans=p[i].r-p[i].l+1;
		int dif=r-p[i].l+1;

		if(dif>0)
			ans-=dif;
//		System.out.println(ans);
		ans=Math.max(ans, 0);
		int take=dp(i+1,Math.max(r, p[i].r),miss)+ans;
		int leave=0;

		if(miss<2)
			leave=dp(i+1,r,miss+1);

		return dp[i][r][miss]=Math.max(take, leave);
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		n=sc.nextInt();q=sc.nextInt();
		dp=new int[q][n][3];
		p=new Pair[q];
		for(int i=0;i<q;i++)
		{
			int left=sc.nextInt();int right=sc.nextInt();
			p[i]=new Pair(left, right);
			for(int j=0;j<n;j++)
				Arrays.fill(dp[i][j], -1);
		}
		Arrays.sort(p);
		System.out.println(dp(0,0,0));
		pw.close();
	}
	static class Pair implements Comparable<Pair>
	{
		int l,r;
		public Pair(int left,int right) {
			// TODO Auto-generated constructor stub
			l=left;r=right;
		}
		@Override
		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			return l==o.l?r-o.r:l-o.l;
		}
		@Override
		public String toString() {
			// TODO Auto-generated method stub
			return l+" "+r;
		}
	}
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

		String nextLine() throws IOException {
			return br.readLine();
		}

		boolean hasnext() throws IOException {
			return br.ready();
		}

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

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

		char[] nextCharArray() throws IOException {
			return br.readLine().toCharArray();
		}

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

	}
}


import java.io.*;
import java.util.*;
public class HelloWorld{

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

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

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

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

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

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

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

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

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

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

    public static void main(String []args){

        InputReader sc = new InputReader(System.in);

        int n = sc.nextInt();

        String str = sc.readString();
        str = reduce(str);
        n = str.length();

        int dp[][] = new int[n][n];

        for(int len=0; len<n; len++){
            for(int begin=0; begin+len<n; begin++){
                int end = begin + len;

                if(len == 0){
                    dp[begin][end] = 1;
                    continue;
                }

                dp[begin][end] = 1 + dp[begin+1][end];

                for(int i=begin+1; i<=end; i++){
                    if(str.charAt(begin) == str.charAt(i))
                        dp[begin][end] = Math.min(dp[begin][end], dp[begin+1][i-1] + dp[i][end]);
                }
            }
        }

        System.out.println(dp[0][n-1]);
    }
}


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

public class B{

	static int n;
	static char []s;
	static int [][][]memo;
	static int dp(int l,int r,int cnt) {
		if(l==r)
			return 1;
		if(l>r)
			return 0;
		if(memo[cnt][l][r]!=0)
			return memo[cnt][l][r];

		int ans=1+dp(l+1,r,1);
		for(int i=l+1;i<=r;i++)
			if(s[i]==s[l])
			{
				ans=Math.min(ans, dp(l+1,i-1,1)+dp(i,r,cnt+1));
			}
		return memo[cnt][l][r]=ans;

	}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		n=sc.nextInt();
		s=sc.next().toCharArray();
		memo=new int [n+1][n][n];
		out.println(dp(0, n-1, 1));

		out.close();

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


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

public class A
{

	static StringBuilder st = new StringBuilder();

	static int [][][] memo ;
	static char [] s ;

	static int dp(int l , int r , int cnt)
	{
		if(l > r) return 0 ;

		if(memo[l][r][cnt] != -1)return memo[l][r][cnt] ;

		int ans  = dp(l + 1, r, 0) + 1 ;

		for(int i = l + 1 ; i <= r ; i++)
			if(s[l] == s[i])
				ans = Math.min(ans, dp(l + 1, i - 1, 0) + dp(i , r , cnt + 1 ));

		return memo[l][r][cnt] = ans ;
	}

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

		int n = sc.nextInt() ;
		s = sc.next().toCharArray() ;
		memo = new int [500][500][500] ;

		for(int i = 0 ; i< 500 ; i++)
			for(int j = 0 ; j < 500 ; j++)
				Arrays.fill(memo[i][j], -1);

		out.println(dp(0, n - 1, 0));
		out.flush();
		out.close();
	}

	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

	}

	static void shuffle(int[] a)
	{
		int n = a.length;
		for (int i = 0; i < n; i++)
		{
			int r = i + (int) (Math.random() * (n - i));
			int tmp = a[i];
			a[i] = a[r];
			a[r] = tmp;
		}
	}

}


import java.util.*

public class Solution {

    int n, m;

    Solution(int n, int m) {
        if (n <= m) {
            this.n = n;
            this.m = m;
        } else {
            this.n = m;
            this.m = n;
        }
    }

    int kth(int k) {
        int lo = 1, hi = n * m;
        while (lo <= hi) {
            int mid = (lo + hi) >>> 1;
            int num = num(mid);
            if (k > num)
                lo = mid + 1;
            else if (k < num)
                hi = mid - 1;
            else
                return floor(mid);
        }
        return floor(lo);
    }

    int num(int v) {
        int k = 0, n = this.n, m = this.m;
        for (int i = 1; i <= n; i++) {
            if (k == (k += Math.min(v / i, m)))
                break;
        }
        return k;
    }

    int floor(int v) {
        while (v > 1) {
            for (int i = n; i > 0; i--) {
                if (v / i > m)
                    break;
                if (v % i == 0)
                    return v;
            }
            v--;
        }
        return 1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println(new Solution(sc.nextInt(), sc.nextInt()).kth(sc.nextInt()));
    }


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

public class Solution {
    public static void main(String args[]) {
    	Scanner in = new Scanner(System.in);
    	int n=in.nextInt(), m=in.nextInt(), k=in.nextLong();
    	long start=1, end=(long)(25*1e10), ans=start, l=start, r=end;
    	while(l<=r) {
    		long mid=(l+r)/2;
    		if(numSmaller(n, m, mid)<k) {
    			ans=mid;
    			l=mid+1;
    		} else
    			r=mid-1;
    	}
    	System.out.println(ans);
    }

    static long numSmaller(int n, int m, long x) {
    	long t=0;
    	for(int i=1; i<=n; ++i)
    		t+=Math.min((x-1)/i, m);
    	return t;
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class Heap {
	long arr[][],di;
	int num;
	Heap(int a){
		arr = new long[a][2];
		num = 0;
		di = 0;
	}
	public void swap(long arr[][],int i,int j){
		long t = arr[i][0];
		arr[i][0] = arr[j][0];
		arr[j][0] = t;
		t = arr[i][1];
		arr[i][1] = arr[j][1];
		arr[j][1] = t;
	}
	public void Minheap(int a){
		while(a>0&&(arr[(a-1)/2][0]>arr[a][0]||(arr[(a-1)/2][0]==arr[a][0]&&arr[(a-1)/2][1]>arr[a][1]))){
			swap(arr,(a-1)/2,a);
			a = (a-1)/2;
		}
	}
	public void Minheapify(int a){
		int largest = a;
		if(2*a+1<num&&(arr[largest][0]>arr[2*a+1][0]||(arr[largest][0]==arr[2*a+1][0]&&arr[largest][1]>arr[2*a+1][1])))
			largest = 2*a+1;
		if(2*a+2<num&&(arr[largest][0]>arr[2*a+2][0]||(arr[largest][0]==arr[2*a+2][0]&&arr[largest][1]>arr[2*a+2][1])))
			largest = 2*a+2;
		if(largest!=a){
			swap(arr,a,largest);
			Minheapify(largest);
		}
	}
	public void insert(long a,long y){
		arr[num++][0] = a;
		arr[num-1][1] = y;
		Minheap(num-1);
	}
	public void deleteAtIndex(int a){
		long pi = arr[a][0];
		long i = arr[a][1];
		arr[a][0] = arr[num-1][0];
		arr[a][1] = arr[num-1][1];
		num--;
		if(arr[a][0]>pi||(arr[a][0]==pi&&arr[a][1]>i))
			Minheapify(a);
		else
			Minheap(a);
	}
	public long getMin(){
		long pi = arr[0][0];
		di = arr[0][1];
		deleteAtIndex(0);
		return pi;
	}
	public long getIndex(){
		return di;
	}
}

public class TestClass {

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	private static void soln() {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		Heap h = new Heap(n);
		for(int i=0;i<n;i++)
			h.insert(i+1, i+1);
		long x=0,y=0;
		for(int i=0;i<k;i++){
			x = h.getMin();
			y = h.getIndex();
			h.insert(x+y, y);
		}
		pw.print(x);
	}
	public static void main(String[] args) {
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Multiplication {
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long n,m,k;

        StringTokenizer st = new StringTokenizer(br.readLine());
        n=Long.parseLong(st.nextToken());
        m=Long.parseLong(st.nextToken());
        k=Long.parseLong(st.nextToken());
        long low=1;
        long high=n*m;

        System.out.println(solve(low, high, n, m,k));

    }
    private static long solve(long low, long high, long n, long m, long k) {
    long mid =0;
    if (low == high)
    	return low;
    else if (k < 2) {
    	return k;
    }
    else if (high==k) {
    	return k;
    }
    else if (high > k && n > k && m> k ) {
    	high =k+1;
    }

	    while(low +1 < high){
	     mid = low + ((high-low) / 2);
	    long[] hmid=f(mid,n,m);
	    long fmid=hmid[0];

	    long gmid=hmid[1];

	   //System.out.println("Before mid "+ mid +" low "+low+" high "+high+" fmid "+ fmid+ " k "+k+ " gmid "+gmid);

	    if(fmid < k && k<= fmid + gmid) {
	    	//System.out.println("hello2");
	    	return mid;
	    }
	    else if (fmid == 0) {
	    	low= low+1;
		     hmid=f(low-1,n,m);
		     fmid=hmid[0];

		     gmid=hmid[1];
  		   //System.out.println("Low mid "+ mid +" low "+low+" high "+high+" fmid "+ fmid+ " k "+k+ " gmid "+gmid);

	    	if(fmid < k && k<= fmid + gmid) {

		    	//System.out.println("hello2");
		    	return low-1;
		    }
		     hmid=f(low,n,m);
		     fmid=hmid[0];

		     gmid=hmid[1];
		     //System.out.println("Low mid "+ mid +" low "+low+" high "+high+" fmid "+ fmid+ " k "+k+ " gmid "+gmid);

	    	if(fmid < k && k<= fmid + gmid) {

		    	//System.out.println("hello2");
		    	return low;
		    }
	    }
	    else if(fmid+gmid<k){
	        low=mid;
	    }
	    else{
	        high=mid;
	    }
		   //System.out.println("After mid "+ mid +" low "+low+" high "+high+" fmid "+ fmid+ " k "+k+ " gmid "+gmid);

	}

    return mid;
    }
    static long []f (long val,long n, long m)
    {
    	long ret = 0;
    	boolean ret1= false;
    	long counter =0;
        for(i=1; i<=n; i++)
			ret+=Math.min(val/i,m);

    	//System.out.println();
        return (ret1)? new long[]{ret-counter,counter}:(long[]) new long[]{0,0};
    }

}


import java.util.*;
public class cf396D {
	public static void main(String []args){
		Scanner sc=new Scanner(System.in);
		long l1=sc.nextLong();
		long r1=sc.nextLong();
		long l2=sc.nextLong();
		long r2=sc.nextLong();
		long k=sc.nextLong();
		if(r1<l2||l1>r2)
			System.out.println(0);
		else{
			if(l2>=l1&&l2<=r1&&r2>r1){
				if(k>=l2&&k<=r1)
					System.out.println(r1-l2);
				else
					System.out.println(r1-l2+1);
			}
			else if(l2>=l1&&l2<=r1&&r2<=r1){
				if(k>=l2&&k<=r2)
					System.out.println(r2-l2);
				else
					System.out.println(r2-l2+1);
			}
			else if(l2<=l1&&r1<=r2){
				if(k>=l1&&k<=r1)
					System.out.println(r1-l1);
				else
					System.out.println(r1-l1+1);
			}
			else if{
				if(k>=l1&&k<=r2)
					System.out.println(r2-l1);
				else
					System.out.println(r2-l1+1);
			}
		}
	}
}


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

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

        PrintWriter pw;
        pw = new PrintWriter(System.out);

        StringTokenizer str = new StringTokenizer(br.readLine());

        long l1 = Long.parseLong(str.nextToken());
        long r1 = Long.parseLong(str.nextToken());
        long l2 = Long.parseLong(str.nextToken());
        long r2 = Long.parseLong(str.nextToken());
        long k = Long.parseLong(str.nextToken());
        long time;

        long left = Math.max(l1,l2);

        long right = Math.min(r2, r1);

        if(right>=left)
        time = right-left+1;

        if((k >= l2 && k <= r1) && time!=0)
        {
            time--;
        }

        pw.println(time);

        pw.close();
    }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.StringTokenizer;

import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Main {

	static class Reader {
		BufferedReader r;
		StringTokenizer str;

		Reader() {
			r = new BufferedReader(new InputStreamReader(System.in));
		}

		Reader(String fileName) throws FileNotFoundException {
			r = new BufferedReader(new FileReader(fileName));
		}

		public String getLine() throws IOException {
			return r.readLine();
		}

		public String getNextToken() throws IOException {
			if (str == null || !str.hasMoreTokens()) {
				str = new StringTokenizer(r.readLine());
			}
			return str.nextToken();
		}

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

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

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

		public String nextString() throws IOException {
			return getNextToken();
		}

		public int[] intArray(int n) throws IOException {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();

			return a;

		}

		public long[] longArray(int n) throws IOException {
			long a[] = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();

			return a;

		}

		public String[] stringArray(int n) throws IOException {
			String a[] = new String[n];
			for (int i = 0; i < n; i++)
				a[i] = nextString();

			return a;

		}

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

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

		Reader r=new Reader();
long l1=r.nextLong();
long r1=r.nextLong();
long l2=r.nextLong();
long r2=r.nextLong();
long k=r.nextLong();
long start =0,end=0;
if(l2<=l1)
{
	start=l1;
}
else if(l2>l1&&l2<=r1)
{
	start=l2;
}
else if(l2>r1)
{
	start=r1;
}

if(r2<l1)
{
	end=r2;

}
else if(r2>=l1&&r2<=r1)
{
	end=r2;
}
else {
	end=r1;
}

long result=end-start+1;
if(k>=start&&k<=end)
{
	result--;
}

System.out.println(result);

	}

}


public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		long l1, r1, l2, r2, k, x, y;

		l1 = scan.nextLong();
		r1 = scan.nextLong();
		l2 = scan.nextLong();
		r2= scan.nextLong();
		k = scan.nextLong();
		x = (long) Math.max(l1, l2);
		y = (long) Math.min(r1, r2);

		if(x <= k && y >= k){
			System.out.println(y - x);
		}
		else if (x <= y){
			System.out.println(y-x+1);
		}
		else{
			System.out.println(0);
		}
	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class BusStop {

    /**
     * @param args
     */
    public static int count(ArrayList<Integer> x){
        int count=0;
        for(int i=0 ; i<x.size();i++){
            count+=x.get(i);
        }
        return count;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
          int x1 , x2,x3,c=0;
            Scanner in = new Scanner(System.in);
            x1 = in.nextInt();
            x2 = in.nextInt();
            ArrayList<Integer> x = new ArrayList<Integer>();
            for(int i=0; i<x1 ; i++){
                 x3 = in.nextInt();
                x.add(x3);
            }

                 }

                else if(x.size()==1)co++;
                 }
             System.out.println(co);
    }

}


import java.util.*;
public class cf1
{
	public static void main(String args[])
	{
		int n,l,f=1,x=0;
		Scanner s=new Scanner(System.in);
		n=s.nextInt();
		int m;
		m=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=s.nextInt();

		}
		x=x+a[i];
		for(int i=1;i<n;i++)
		{
			if(x<=m)
			{
				x=x+a[i];

			}

			else
			{
				f++;
				x=[i];
			}

		}
		System.out.println(f);

	}
}


import java.io.*;
import java.util.Scanner;
public final class x{
public static void main(String[] args){

Scanner hp = new Scanner(System.in);

String[] nm = hp.nextLine().split(" ");
int n = Integer.parseInt(nm[0]);
int m = Integer.parseInt(nm[1]);
String[] gs = hp.nextLine.split(" ");
int[] g = new int[gs.length];
for(int i = 0; i < gs.length; i++){
g[i]=Integer.parseInt(gs[i]);
}
//if (g.length != n) throw new Exception();
int c = 0;

for (int i = 0; i < n; i++){
//if(g[i]>m) throw new Exception();
c++;
int r = g[i];
while(i+1<n){
r += g[i+1];
if(r>m) break;
i++;
}
}
System.out.println(c);
}
}


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

package sp5;
import static java.lang.System.out;
import java.util.Scanner;
/**
 *
 * @author Алексейка
 */
public class sp5 {
      public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       int a = in.nextInt();
        int massBass = in.nextInt();
       int[] b = new int[101];
       int counter = 0;
       int temp = 0;
       int var = 0;
       for(int i = 0; i < a; i++){
           b[i] = in.nextInt();
           }
       for(int i = 0; i <a;i++){
           if(temp + b[i] < massBass){
             temp+=b[i];
           }
           else{
               temp = b[i];
               counter++;
           }
       }
       out.println(counter);
       }

      }


mport java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
import java.util.concurrent.atomic.AtomicLong;

public class C {
    private final static long START_TIME=System.currentTimeMillis();
    private final static boolean LOG_ENABLED=true;
    private final static boolean ONLINE_JUDGE = LOG_ENABLED && (System.getProperty("ONLINE_JUDGE") != null);
    private final static String SYSTEM_ENCODING="utf-8";

    private static class Logger{
        private final PrintWriter logWriter=Util.newPrintWriter(System.err,true);
        private final DecimalFormat df=new DecimalFormat("0.000");
        private void message(String type, String message, Object ... params){
            if(ONLINE_JUDGE){
                return;
            }
            logWriter.printf("["+type+"] "+df.format((System.currentTimeMillis()-START_TIME)/1000.0)+": "+message+"\r\n", params);
        }
        public void debug(String message, Object ... params){
            message("DEBUG", message, params);
        }
    }

    private final static class Util{
        public static PrintWriter newPrintWriter(OutputStream out, boolean autoFlush){
            try {
                return new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(out), SYSTEM_ENCODING),autoFlush);
            } catch (UnsupportedEncodingException e) {
                throw new IllegalStateException(e);
            }
        }
    }

    public final static class FastScanner{
        private BufferedReader reader;
        private StringTokenizer currentTokenizer;
        public FastScanner(Reader reader) {
            if(reader instanceof BufferedReader){
                this.reader=(BufferedReader) reader;
            }else{
                this.reader=new BufferedReader(reader);
            }
        }

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

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

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

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

    }

    private final static Logger log=new Logger();
    private final BufferedReader reader;
    private final FastScanner in;
    private final PrintWriter out=Util.newPrintWriter(System.out,false);
    private int[] digits;
    private int digitCount;
    private AtomicLong result;
    private int[] maxDigit;

    public C(BufferedReader reader){
        this.reader=reader;
        in=new FastScanner(this.reader);
    }

    public static void main(String[] args) throws IOException {
        log.debug("Started");
        try{
            new C(new BufferedReader(new InputStreamReader(System.in, SYSTEM_ENCODING))).run();
        }finally{
            log.debug("Stopped");
        }
    }

    void run(){
        solve();
        out.flush();
    }

    private void solve(){
        char[] charDigits = new StringBuilder(in.next()).reverse().toString().toCharArray();
        digits=new int[charDigits.length];
        maxDigit=new int[charDigits.length];
        digitCount = digits.length;
        for(int i=0;i<digits.length;i++){
            digits[i]=charDigits[i]-'0';
        }
        updateMaxDigit(digitCount-1);

        result=new AtomicLong(0);

        solveInternal();
        out.print(result);
    }

    private void updateMaxDigit(int fromIndex) {
        if(fromIndex==digitCount-1){
            maxDigit[fromIndex]=digits[fromIndex];
            fromIndex--;
        }

        while(fromIndex>=0){
            maxDigit[fromIndex]=Math.max(digits[fromIndex], maxDigit[fromIndex+1]);
            fromIndex--;
        }
    }

    private void solveInternal() {
        while(true){
            if(digitCount==1){
                if(digits[0]!=0){
                    result.incrementAndGet();
                }
                return;
            }
            substractMax();
            result.incrementAndGet();
        }

    }

    private void substractMax() {
        int i=0;
        digits[i]-=maxDigit[0];
        if(maxDigit[0]==0){
            throw new IllegalStateException();
        }
        while(digits[i]<0){
            digits[i]+=10;
            digits[i+1]--;
            i++;
        }
        if(i==digitCount-1 && digits[digitCount-1]==0){
            digitCount--;
            i--;
        }

        updateMaxDigit(i);

    }
}


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

public class NTM {

    public static int highestDigit(int n) {
        String s = ""+n;
        int h=0;
        for(int i = 0 ; i < s.length(); ++i) {
            if(s.charAt(i)>h) h = Integer.parseInt(s.charAt(i)+"");
        }
        return h;
    }

 public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int n = sc.nexInt();
     int i = 0;
     for(;n!=0;++i) {
         n-=highestDigit(n);
     }
     System.out.println(n);
 }
}


import java.util.Scanner;

public class TheGreatJulyaCalendar_331C1 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int num = (int)num/10;
        int ans = num == 0 ? 0 : num * 2 + 1;
        System.out.println(ans);
    }
}


import java.util.*;

import java.io.*;

public class mm{

	static Long find(String s)
	{
		if(s.length()==1 && s.charAt(0)=='0')
			return 0;
		if(s.length()==1)
			return 1l;
int max = 0;
		for(int i=0;i<s.length();i++)
		{
			max = Math.max(max,s.charAt(i)-'0');
		}

		Long l = Long.parseLong(s);
		l = l-max;

		return 1+find(String.valueOf(l));

	}
	public static void main(String[] args) {

		Scanner sc = new Scanner();

		String s = sc.nextLine();

		out.println(find(s));
		out.close();

	}
	static	PrintWriter out=new PrintWriter(System.out);
	static class Scanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String nextLine() {
			while (!st.hasMoreTokens())
				try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextLine());
		}
		long nextLong() {
			return Long.parseLong(nextLine());
		}
	}

}


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

import java.io.*;

public class Main implements Runnable {

    public static void main(String[] args) {
        new Thread(null, new Main(), "whatever", 1 << 26).start();
    }

    private FastScanner sc;
    private PrintWriter pw;

    public void run() {
        try {
            // pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
            // sc = new FastScanner(new BufferedReader(new FileReader("input.txt")));
            pw = new PrintWriter(System.out);
            sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        } catch (Exception e) {
            throw new RuntimeException();
        }
        int t = sc.nextInt();
        // int t = 1;
        while (t-- > 0) {
            solve();
        }
        pw.close();
    }

    public long mod = 1_000_000_007;

    public void solve() {
        int n = sc.nextInt(), k = sc.nextInt();
        for (int i = 0; i < k; i++) ans = (ans * n) % mod;
        pw.println(ans);
    }

    class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(BufferedReader bf) {
            reader = bf;
            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 float nextFloat() {
            return Float.parseFloat(next());
        }

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

        public String[] nextStringArray(int n) {
            String[] a = new String[n];
            for (int i = 0; i < n; i++) {
                a[i] = next();
            }
            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.util.*;

import jdk.internal.net.http.common.Log;

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

public class B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        while (t > 0) {
            t--;
            int n = s.nextInt();
            int k = s.nextInt();
            long ans = 1;
            long base = n;
            long MOD = 1000000007;
            while (k != 0) {
                if ((k & 1) == 1)
                    ans = ans * base % MOD;
                base = base * base % MOD;
                k >>= 1;
            }
            System.out.println(ans);
        }
        s.close();
    }
}


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

public class SUm0 {
    public static void main(String[] args) {
        handmadeInput.FastReader in = new handmadeInput.FastReader();
        int t = in.nextInt();
        StringBuilder s = new StringBuilder();
        while (t-- > 0) {
            int n = in.nextInt();
            int k = in.nextInt();
            int mod = 1000000007;
            int ans = 1;
            BigInteger bigInteger = new BigInteger("1");
            for (int i = 1; i <= k; i++) {
                bigInteger = bigInteger.multiply(new BigInteger(String.valueOf(n)));
            }
            bigInteger = bigInteger.mod(new BigInteger(String.valueOf(mod)));
            s.append(bigInteger).append(" ");
        }
        System.out.println(s);
    }
}

// Additional Classes go here

class handmadeInput {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

class UtilityFunctions {
    //! returns gcd of given numbers
   public int gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

 public int primeFactors(int n) {
        HashMap<Integer, Integer> hashMap = new HashMap<>(n);
        int c = 0;

        // Print the number of 2s that divide n
        while (n % 2 == 0) {
//            if (hashMap.containsKey(2)) {
//                hashMap.replace(2, hashMap.get(2) + 1);
//            } else {
//                hashMap.put(2, 1);
//            }
            c++;
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            // While i divides n, print i and divide n
            while (n % i == 0) {
                //System.out.print(i + " ");

//                if (hashMap.containsKey(i)) {
//                    hashMap.replace(i, hashMap.get(i) + 1);
//                } else {
//                    hashMap.put(i, 1);
//                }
                c++;
                n /= i;
            }
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2) {

//            if (hashMap.containsKey(n)) {
//                hashMap.replace(n, hashMap.get(n) + 1);
//            } else {
//                hashMap.put(n, 1);
//            }
            c++;
        }

        //System.out.print(n);
        return c;
    }
}


// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class ll
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static int findIndex(long arr[], long t)
    {

        // if array is Null
        if (arr == null) {
            return -1;
        }

        // find length of array
        int len = arr.length;
        int i = 0;

        // traverse in the array
        while (i < len) {

            // if the i-th element is t
            // then return the index
            if (arr[i] == t) {
                return i;
            }
            else {
                i = i + 1;
            }
        }
        return -1;
    }

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

    // method to return LCM of two numbers
    static int lcm(int a, int b)
    {
        return (a / gcd(a, b)) * b;
    }
    public static int[] swap(int a[], int left, int right)
    {

        // Swap the data
        int temp = a[left];
        a[left] = a[right];
        a[right] = temp;

        // Return the updated array
        return a;
    }
    public static int[] reverse(int a[], int left, int right)
    {

        // Reverse the sub-array
        while (left < right) {
            int temp = a[left];
            a[left++] = a[right];
            a[right--] = temp;
        }

        // Return the updated array
        return a;
    }
    public static int[] findNextPermutation(int a[])
    {
        int last = a.length - 2;

        // find the longest non-increasing suffix
        // and find the pivot
        while (last >= 0) {
            if (a[last] < a[last + 1]) {
                break;
            }
            last--;
        }

        // If there is no increasing pair
        // there is no higher order permutation
        if (last < 0)
            return a;

        int nextGreater = a.length - 1;

        // Find the rightmost successor to the pivot
        for (int i = a.length - 1; i > last; i--) {
            if (a[i] > a[last]) {
                nextGreater = i;
                break;
            }
        }

        // Swap the successor and the pivot
        a = swap(a, nextGreater, last);

        // Reverse the suffix
        a = reverse(a, last + 1, a.length - 1);

        // Return true as the next_permutation is done
        return a;
    }
    static int factorial(int n)
  {
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
  }
    public static void main(String[] args)
    {
            FastReader d=new FastReader();
            int t,i,j,c,z,k,l,n;
            int mod = (int) 1e9 + 7;

            int Inf=Integer.MAX_VALUE;
            int negInf=Integer.MIN_VALUE;
        t=d.nextInt();
        //t=1;
        //String s;
        //char ch,ch1,ch2,ch3;
        while(t-->0)
        {
            z=c=0;
            long nn=d.nextLong();
            long kk=d.nextLong();
            //int a[]=new int[n];
            //for(i=0;i<n;i++)
            //a[i]=d.nextInt();
            long xx;
            for(i=1;i<=kk;i++)
            xx*=nn%mod;
            System.out.println(xx);
            //s=d.nextLine();//dont need extra d.nextLine()
        }
    }
}