import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String number = sc.next();
        Integer firstPart = Integer.parseInt(number.substring(0,3));
        Integer secondPart = Integer.parseInt(number.substring(3,6));

        List<Integer> firstPartDigits = new ArrayList<>();
        List<Integer> secondPartDigits = new ArrayList<>();
        int firstPartDigitsSum = 0;
        int secondPartDigitsSum = 0;
        while (firstPart > 0) {
            firstPartDigits.add(firstPart % 10);
            firstPartDigitsSum += firstPart % 10;
            firstPart /= 10;

            secondPartDigits.add(secondPart % 10);
            secondPartDigitsSum += secondPart % 10;
            secondPart /= 10;
        }
        Collections.sort(firstPartDigits);
        Collections.sort(secondPartDigits);

        int digitReplacementNeeded = 0;
        while (firstPartDigitsSum != secondPartDigitsSum) {
            if (Math.abs(firstPartDigitsSum - secondPartDigitsSum) < 9) {
                digitReplacementNeeded += 1;
                System.out.println(digitReplacementNeeded);
                return;
            }

            if (firstPartDigitsSum < secondPartDigitsSum) {
                firstPartDigitsSum += Math.min(9 - firstPartDigits.get(digitReplacementNeeded), secondPartDigitsSum - firstPartDigitsSum);
            } else {
                secondPartDigitsSum += Math.min(9 - secondPartDigits.get(digitReplacementNeeded), firstPartDigitsSum - secondPartDigitsSum);
            }
            digitReplacementNeeded++;
        }

        System.out.println(digitReplacementNeeded);
    }
}
close


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

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

	void solve() throws IOException {
		char[] a = ns().toCharArray();
		int s = 0;
		int i = 0;
		for (; i < a.length / 2; i++)
			s += a[i] - '0';
		for (; i < a.length; i++)
			s -= a[i] - '0';
		int d[] = new int[a.length];
		for (i = 0; i < a.length; i++)
			d[i] = s * (2 * i - 5) > 0 ? '9' - a[i] : a[i] - '0';

		s = Math.abs(s);
		Helper.tr(s, d);
		Arrays.sort(d);
		for (i = 0; i < a.length && s > 0; i++)
			s -= d[a.length - 1 - i];
		out.println(i);
	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

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

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

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

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

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

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

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

		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}


import java.util.*;
public class x
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i=0,x=0;

        for(i=1;i<=n;i++)
        {
             x = x + Math.pow(-1,i)*i;
        }

        System.out.println(x);

    }
}


import java.util.Scanner;

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

		int t = sc.nextInt();

		System.out.println((t%2 != 0) ? n/2 : -(n/2+1));
	}
}


import java.util.Scanner;
public class CalculatingFunction {

    public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
       int n=in.nextInt();
       int count=0;
          //i==odd count= count-i;
           if(n%2==0){
               n=n/2;
           }
               else
               n=(n/2)*(-1)-1;

        System.out.println(n);
    }


import java.util.*;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
 long x,y;
 long result=0;
 Scanner sc=new Scanner(System.in);
 x=sc.nextlong();
 for(int i=1;i<=x;i++)
   {
  if(i%2==0)
  {
    y=1;
  }
  else
  {
    y= -1;
  }
    result+=y*i;
   }
   System.out.println(result);
  }
}


import java.util.Scanner;

public class Main{

    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        String str = in.next();
        if(chech(str)){
            System.out.println(”yes”);
        } else {
            System.out.println(“no”);
        }
    }

    public static boolean check(String str){
        int counter =0;
        for(int i= str.length()-1; i >= 0; i-=1){
            if(str.chatAt(i) == ’0’){
                counter++;
            } else if(counter >= 6){
                return true;
            }
        }
        return false;
    }
}


import java.util.*;

public class Div64
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int z = 0, o = 0;
		for (int i = s.length - 1; i >= 0; i--)
		{
			if (s.charAt(i) == '0')
				z++;
			else if (z >= 6)
			{
				o++;
			}
		}
		if (z >= 6 && o == 1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


/*
 * 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 codeforces;

//import java.util.Scanner;

/**
 *
 * @author HOME
 */
public class Main {
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);
        String g = sc.next();
        int t = Integer.parseInt(g, 2);
        if(t>= 64)
            System.out.println("yes");
        else
            System.out.println("no");

        }
    }


import java.util.Scanner;

public class Main{

    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        String str = in.next();
        if(chech(str)){
            System.out.println("yes");
        } else {
            System.out.println("no");
        }
    }

    public static boolean check(String str){
        int counter =0;
        for(int i= str.length()-1; i >= 0; i-=1){
            if(str.chatAt(i) == (char)0){
                counter++;
            } else if(counter >= 6){
                return true;
            }
        }
        return false;
    }
}


import java.util.*;
public class panagram
{
    public static void main(String [] args)
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
    String   s=(in.next()).toLowerCase();
       String s1="abcdefghijklmnopqrstuvwxyz";
       boolean s1=Pattern.matches(s1,s);

        if(s1==true)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }
}


/*
 * 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 pangram;

import java.util.Scanner;

/**
 *
 * @author belar
 */
public class Pangram {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) {
        // TODO code application logic here
        String letras = "abcdefghijklmnopqrstuvwxyz";
        Scanner leer = new Scanner(System.in);
        int n = Integer.valueOf(leer.nextLine());
        String ca = leer.nextLine();
        ca = ca.toLowerCase();
        boolean es = false;
        int nro = 0;
        if(ca.length()>=26){
            for(int i =0;i<n;i++){
                if(!letras.contains(String.valueOf(ca.charAt(i)))){
                    es = false;
                    break;
                }
                nro++;
            }
            if(nro == 26){
                es = true;
            }
        }else{
            es = false;
        }

        if(es)
            System.out.println("YES");
        else
            System.out.println("NO");

    }

}


import java.util.*;
import java.lang.*;
public class Main
{
    public static void main(String args[])
    {
        String s;
        Scanner sc=new Scanner(System.in);
        s=sc.next();
        s=s.toLowerCase();
        String ref="abcdefghijklmnopqrstuvwxyz";
        char ch[]=s.toCharArray();
        Arrays.sort(ch);
        String s1="";
        for(int i=ch.length-1;i>=0;i--)
        {
            s1+=ch[i]+"";
        }
        if(s1.equals(ref))
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
        }
    }
}


import java.util.*;
public class a
{
    public void main()
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.nextLine();
        int count[]=new int[1000];int c=0;int k=0;int m=0;
        s=s.toUpperCase();
        for(int a=65;a<=90;a++)
        {
            for(int j=0;j<s.length();j++)
            {
                if(s.charAt(j)==(char)a)
                {
                c=c+1;
            }
        }
                    count[k]=c;
                    k++;
                    c=0;
    }
    for(int l=0;l<k;l++)
    {
        if(count[l]>=1)
        m++;
    }
    if(m==26)
    return "YES";
    else
    return "NO";
}
}


import java.util.*;

public class Main
{

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

        String input = Sc.nextLine();

        input = input.replaceAll("\\s" , "");

        char c = input.charAt(input.length - 2);

        if(c == 'A' || c == 'a' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U' || c=='y' || c == 'Y')
        {
            System.out.println("YES");

        }
        else
        {
            System.out.println("NO");
        }
    }
}


public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		String cad = in.nextLine();
		if (cad.charAt(cad.length()-2) == ' ')
		{
			if (cad.charAt(cad.length()-3) == 'a' || cad.charAt(cad.length()-3) == 'e' || cad.charAt(cad.length()-3) == 'i' || cad.charAt(cad.length()-3) == 'o' || cad.charAt(cad.length()-3) == 'u' || cad.charAt(cad.length()-3) == 'y' || cad.charAt(cad.length()-3) == 'A' || cad.charAt(cad.length()-3) == 'E' || cad.charAt(cad.length()-3) == 'I' || cad.charAt(cad.length()-3) == 'O' || cad.charAt(cad.length()-3) == 'U' || cad.charAt(cad.length()-3) == 'Y')
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
		else
		{
			if (cad.charAt(cad.length()-2) == 'a' || cad.charAt(cad.length()-2) == 'e' || cad.charAt(cad.length()-2) == 'i' || cad.charAt(cad.length()-2) == 'o' || cad.charAt(cad.length()-2) == 'u' || cad.charAt(cad.length()-2) == 'y' || cad.charAt(cad.length()-2) == 'A' || cad.charAt(cad.length()-2) == 'E' || cad.charAt(cad.length()-2) == 'I' || cad.charAt(cad.length()-2) == 'O' || cad.charAt(cad.length()-2) == 'U' || cad.charAt(cad.length()-2) == 'Y')
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class A_ {
    private boolean isVowel(char s){
        ArrayList <Character> a = new ArrayList<Character>();
        a.add('a');a.add('i');a.add('e');a.add('o');a.add('u');a.add('y');
        a.add('A');a.add('I');a.add('E');a.add('O');a.add('U');a.add('Y');
        if (a.contains(s))return true;
        return false;
    }
    public static void main(String[] args) throws IOException{
        BufferedReader stdin = new BufferedReader(new InputStreamReader(
                System.in));

        String s =stdin.readLine();
        for(int i=s.length() - 1 ; i>=0 ; i--){
            if (s.charAt(i)!='?' && s.charAt(i)!=' '){
                if (new A_().isVowel(s.charAt(i))){
                    System.out.println("YES");
                    break;
                }
                else{
                System.out.println("NO");
                break;
                }

            }
        }
        }


import java.util.*;

public class Main
{

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

        String input = Sc.nextLine();

        input = input.replaceAll("\\s" , "");

        char c = input.charAt(input.length - 2);

        if(c == "A" || c == "a" || c == "e" || c == "E" || c == "I" || c == "i" || c == "o" || c == "O" || c == "u" || c == "U" || c=="y" || c == "Y")
        {
            System.out.println("YES");

        }
        else
        {
            System.out.println("NO");
        }
    }
}


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

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

	public class Main (String[] args) throws java.lang.Exception
	{
		int n, m, k;
		Scanner in = new Scanner(System.in);
        n =  in.nextInt();
        m =  in.nextInt();
        k =  in.nextInt();
        in.close();
        long [][] bricks = new long[2001][2000];
        bricks[1][0] = m;
        for(int i = 2; i <= n; ++i)
        	for(int j = 0; j <= k; ++j)
        		if(j == 0)
					bricks[i][j] = m % 998244353;
				else
					bricks [i][j] = (bricks[i-1][j] + bricks[i-1][j-1]*(m-1))% 998244353;
		System.out.print(bricks[n][k]);
	}


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

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

static		void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			int m = in.nextInt();
			int k = in.nextInt();
			int mod = 998244353;
			long[][] dp = new long[n + 1][k + 2];
			dp[1][0] = m;
			for (int i = 2; i <= n; i++)
				for (int j = 0; j <= k; j++) {
					dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
					dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j] * (m - 1) % mod) % mod;
				}
			out.println(dp[n][k]);
		}
	}

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

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

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

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

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

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

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

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

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

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


import java.util.*;
public class Abc {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();

		long fact[] = new long[2001];
		long mod = 998244353;

		fact[0] = 1;
		for(int i = 1; i < n ; i++) {
			fact [i] = (i * fact[i - 1]) % mod;
		}

		long c = comb(n - 1, k, fact, mod);
		c = (c * m) % mod;
		if(k > 1) {
			c = (c * pow(m - 1, k, mod)) % mod;
		}
		if(m == 1 && k > 0) {
			System.out.pritnln(0);
		} else {
			System.out.println(c);
		}
	}
	static long comb(int a, int b, long fact[], long c) {
		if(b == 0) {
			return 1;
		}
		long num = fact[a];
		long denom = (fact[b] * fact[a - b]) % c;
		return (num * modInverse(denom, c)) % c;
	}
	static long modInverse(long a, long b) {
		return pow(a, b - 2, b);
	}
	static long pow(long a, long b, long mod) {
		long result = 1;
		while(b > 0) {
			if(b % 2 == 1) {
				result = (result * a) % mod;
			}
			a = (a * a) % mod;
			b /= 2;
		}
		return result;
	}
}


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

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

	public class Main
	{
		int n, m, k;
		Scanner in = new Scanner(System.in);
        n =  in.nextInt();
        m =  in.nextInt();
        k =  in.nextInt();
        in.close();
        long [][] bricks = new long[2001][2000];
        bricks[1][0] = m;
        for(int i = 2; i <= n; ++i)
        	for(int j = 0; j <= k; ++j)
        		if(j == 0)
					bricks[i][j] = m % 998244353;
				else
					bricks [i][j] = (bricks[i-1][j] + bricks[i-1][j-1]*(m-1))% 998244353;
		System.out.print(bricks[n][k]);
	}


import java.util.*;
import java.util.Scanner.*;
import java.io.*;
import java.util.Arrays;
import java.math.*;
import java.math.BigInteger.*;
import java.math.BigDecimal.*;
import java.util.Set.*;

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

        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        Scanner sc= new Scanner (System.in);
         long m,n,b,s=0,x;
         m=sc.nextInt();
         b=sc.nextInt();
        for(int i=0;i<=b;i++){
            x=(b-i)*m;
            s=Math.max(s,((i+1)*(x+1)*(i+x))/2);
        }
        System.out.printf("%u\r\n",s);
    }
}


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

public class C {

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

	C() {

		Scanner in = new Scanner(System.in);

		int len = in.nextInt();
		int rem = 0,count=0;
		ArrayList<Integer> a = new ArrayList<Integer>(len);

		for(int t=0;t<2*len;t++){
			//System.out.println(a);
			if(in.next().equals("add")){
				int n = in.nextInt()-1;
				a.add(n);
			}else{ //remove
				if(a.get(a.size()-1)!=rem++){
					Collections.sort(a,Collections.reverseOrder());
					count++;
				}
				a.remove(a.size()-1);
			}
		}

		System.out.println(count);

		in.close();

	}

}

/*

3
add 1
remove
add 2
add 3
remove
remove

7
add 3
add 2
add 1
remove
add 4
remove
remove
remove
add 6
add 7
add 5
remove
remove
remove

 */


import java.util.*;
public class banana{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long m=sc.nextInt();
        long b=sc.nextInt();
        long maxX=m*b;
        long ans=0,temp;
        long y;
        for(long x=0;x<=maxX;x++){
            y=(long)((-1/(double)m)*x+b);
            temp=((x+1)(y+1)(x+y))/2;
            ans=(long)Math.max(ans,temp);
        }
        System.out.println(ans);
    }
}


import java.util.Scanner;

/**
 *
 * @author Destarte
 */
public class NewClass {

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

        if(m==b && b==1){

 System.out.println(1);
return 1;

}

        int my = b;
        int mx = -b * -m;

        int x0 = -1, y0 = -1;

        for (int y = my; y >= 0; y--) {
            for (int x = mx; x >= 0; x--) {
                double d = ( (double)-1/m) * x + b;
                if (y == d && (y != my && x != 0) && (x != mx && y != 0)) {
                    if (y * x >= y0 * x0) {
                        y0 = y;
                        x0 = x;
                    }
                }
            }
        }

        int soma = 0;

        for (int i = 0; i <= x0; i++) {
            for (int j = 0; j <= y0; j++) {
                soma += i+j;
            }
        }
        System.out.println(soma);

    }
}


import java.util.*;
 public class codechef2
{
	public static void main(String ar[])
	{
	Scanner sc=new Scanner(System.in);
		long v,e;
		v=sc.nextLong();
		e=sc.nextLong();
		if(e==0)System.out.print(v);System.out.print(' ');
		else if(v<=2*e)System.out.print("0 ");
		else System.out.print((v-2*e));System.out.print(' ');

	if(e==0)System.out.print(v+' ');
		else if(e==1)System.out.print(v-2);
		for(long i=2;i<v;i++)
		{
			if(i*(i-1)/2<e&&e<=(i+1)*i/2){System.out.print(v-i-1);break;}
		}

	}

}


import java.util.*;
import java.lang.*;
import java.io.*;
public class D{

    public static int bs(int v,int e){
        long l = 1, r = v;
        while (l <= r)
        {
            long m = l + (r-l)/2;
            if((m*(m-1))/2 == e)
                return (int)m;

            if ((m*(m-1))/2 < e){
                l = m + 1;
                if((l*(l-1))/2>e)
                    return (int)l-1;
            }
            else
                r = m - 1;
        }
        return 0;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long v = sc.nextLong();
        long e = sc.nextLong();
        long min=0,max=0;
        long n;
        if(e==0)
            System.out.println(v+" "+v);
        else{
            min = v - 2*e;
            if(min<=0)
                min = 0;

            long n = bs(v,e);
            if((n*(n-1))/2==e)
                max = v-(int)n;
            else
                max = v-(int)n-1;
            System.out.println(min+" "+max);
            }
    }
}


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

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

    static class BVasyaAndIsolatedVertices {
        public void solve(int testNumber, inclass in, PrintWriter out) {
            long n = in.nextInt(), m = in.nextLong();
            if (m == 0) {
                out.println(n + " " + n);
                return;
            }
            if (m >= n) {
                out.println(0 + " " + 0);
            } else {
                long max = n - m - 1;
                long min = n - (2 * m);
                out.println((min < 0 ? 0 : min) + " " + (max < 0 ? 0 : max));
            }
        }

    }

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

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

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

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

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

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

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

        }

    }
}


import java.util.Scanner;

public class vasyaandisolatedvertices {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long m = in.nextLong();

		long min = 0;
		long max = 0;
		if(n==1) {
			System.out.println("1 1");
			return;
		}
		min = Math.max(0,n-m*2);

		int rem = m;
		int delete = 1;
		while(rem>0) {
			rem-=Math.min(delete,rem);
			delete++;
		}

		if(delete==1) max = n;
		else max = n-delete;

		System.out.println(min +" " +max);
	}
}


import java.util.*;

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

        int n = sc.nextInt();
        int d = sc.nextInt();
        sc.nextLine();

        int[] t = new int[n];
        int sumOfTime = 0;
        for(int i=0; i<t; i++){
            t[i] = sc.nextInt();
            sumOfTime += t[i];
        }

        if(d < (sumOfTime + (n-1)*10)){
            System.out.println("-1");
        }
        else{
            int noOfJokes = (n-1)*2;
            int remainingTime = d - (sumOfTime + (n-1)*10);
            noOfJokes += noOfJokes/5;

            System.out.println(noOfJokes);
        }
    }
}


import java.util.*;

public class col
{
    public static void main(String[] args)
    {
       	Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
	    int d = sc.nextInt();
	    int a[] = new int[n];
	    int sum = 0,ans =0;
	    for(int i=0;i<n;i++)
	    {
	        a[] = sc.nextInt();
	        sum += a[i];
	    }
	    if(sum%5 == 0) ans = -1;
	    else
	    {
	        ans = (d-sum)/5;
	    }
		System.out.println(ans);
    }
}


import java.util.*;
public class MyClass {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int a[]=new int[n];
        int s=0;
        for(int i=0;i<n;i++)
        {
            a[i]=sc.nextInt();
            s+=a[i];
        }
        if((d>=((n-1)*10))
        {
            System.out.println(d/5);
        }
        else
            System.out.println(-1);
    }
}


import java.util.Scanner;

public class Concert {

    public static void main(String []args){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int d = s.nextInt();
        int t[] = new int [n];
        for(int i = 0; i<n; i++){
            t[i] = s.nextInt();
        }
        int count = 0;
        int partialSum = 0;
        int jokes = 0;
        for(int i = 0; i<n; i++){
            partialSum += t[i];
            if(partialSum <= d){
                count ++;
            }else{
                break;
            }
            partialSum += 5;
            if(partialSum <=d){
                jokes ++;
            }else{
                break;
            }
            partialSum +=5;
            if(partialSum<=d){
                jokes++;
            }else{
                break;
            }
        }
        int rest = d-partialSum;
        if(rest > =5){
            jokes += (rest / 5);
        }
        if(count == n){
            System.out.println(jokes);
        }else{
            System.out.println("-1");
        }
    }
}


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

 public class Param
{

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

		Scanner param=new Scanner(System.in);
		String s=param.next();
		String p=param.next();
		//System.out.println(s);
	   // System.out.println(p);
	   String[]arr=s.split(":");
	   int h1 = Integer.parseInt(arr[0]);
       int m1 = Integer.parseInt(arr[1]);
	   String[]arr1=p.split(":");
	   int h2 = Integer.parseInt(arr1[0]);
       int m2 = Integer.parseInt(arr1[1]);
       int h3=0;
       int m3=0;
       if(m1==0&&m2==0&&(h1+h2)%2!=0){
           m3=30;
           h3=(h1+h2)/2;
           String formattedStr1 = String.format("%02d", h3);
            System.out.println(formattedStr1+":"+m3);
          // System.out.println(h3+":"+m3);
       }
       else if(m1==0&&m2!=0&&(h1+h2)%2!=0) {
          m3=(60+m2)/2;
          String formattedStr = String.format("%02d", m3);

            h3=(h1+h2)/2;
             String formattedStr1 = String.format("%02d", h3);
            System.out.println(formattedStr1+":"+formattedStr);
       }
       else{

           if(m1+m2>=60){
              if(h1=!h2)
           m3=Math.abs((60-(m1+m2))/2);
           h1=h1+1;
           }
           else{
              m3=(m1+m2)/2;
           }
           else{
              m3=(m1+m2)/2;
              h1=h1;
           }
           //System.out.println(m3);
           String formattedStr = String.format("%02d", m3);

            h3=(h1+h2)/2;
             String formattedStr1 = String.format("%02d", h3);
            System.out.println(formattedStr1+":"+formattedStr);

       }
      // System.out.println(h3+":"+formattedStr);

    }

}


import java.io.*;
public class middle
{
 public static void main(String args[])throws IOException
 {
  InputStreamReader read=new InputStreamReader(System.in);
  BufferedReader in=new BufferedReader(read);
  int h1,h2,m1,m2,m;
  String a,b;
  a=in.readLine();
  b=in.readLine();
  h1=Integer.parseInt(a.substring(0,2));
  m1=Integer.parseInt(a.substring(3));
  h2=Integer.parseInt(b.substring(0,2));
  m2=Integer.parseInt(b.substring(3));
  m=(h2-h1)*60+(m2-m1);
  m=m/2;
  h1+=(m/60);
  m1+=(m%60);
  if(m1>=60)
  {
   m1-=60;
   h1+1;
  }
  if(h1<10)
  System.out.print("0");
  System.out.print(h1+":"+m1);
 }
}


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

 public class Param
{

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

		Scanner param=new Scanner(System.in);
		String s=param.next();
		String p=param.next();
		//System.out.println(s);
	   // System.out.println(p);
	   String[]arr=s.split(":");
	   int h1 = Integer.parseInt(arr[0]);
       int m1 = Integer.parseInt(arr[1]);
	   String[]arr1=p.split(":");
	   int h2 = Integer.parseInt(arr1[0]);
       int m2 = Integer.parseInt(arr1[1]);
       int h3=0;
       int m3=0;
       if(m1==0&&m2==0&&(h1+h2)%2!=0){
           m3=30;
           h3=(h1+h2)/2;
           String formattedStr1 = String.format("%02d", h3);
            System.out.println(formattedStr1+":"+m3);
          // System.out.println(h3+":"+m3);
       }
       else if(m1==0&&m2!=0&&(h1+h2)%2!=0) {
          m3=(60+m2)/2;
          String formattedStr = String.format("%02d", m3);

            h3=(h1+h2)/2;
             String formattedStr1 = String.format("%02d", h3);
            System.out.println(formattedStr1+":"+formattedStr);
       }
       else{

           if(m1+m2>=60){
              if(h1=!h2){
           m3=Math.abs((60-(m1+m2))/2);
           h1=h1+1;
              }
           }
           else{
              m3=(m1+m2)/2;
           }
           else{
              m3=(m1+m2)/2;
              h1=h1;
           }
           //System.out.println(m3);
           String formattedStr = String.format("%02d", m3);

            h3=(h1+h2)/2;
             String formattedStr1 = String.format("%02d", h3);
            System.out.println(formattedStr1+":"+formattedStr);

       }
      // System.out.println(h3+":"+formattedStr);

    }

}


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

public class Level   {

         public static void main(String[] args) {
              DS.Scanner in =new DS.Scanner();
              String s1=in.next();
              String s2=in.next();
              String h1s="";
              String m1s="";
              String h2s="";
              String m2s="";
              h1s+=s1.charAt(0);h1s+=s1.charAt(1);
              m1s+=s1.charAt(3);m1s+=s1.charAt(4);
              h2s+=s2.charAt(0);h2s+=s2.charAt(1);
              m2s+=s2.charAt(3);m2s+=s2.charAt(4);
              int h1=Integer.valueOf(h1s);
              int m1=Integer.valueOf(m1s);
              int h2=Integer.valueOf(h2s);
              int m2=Integer.valueOf(m2s);
              int total1=h1*60+m1;
              int total2=h2*60+m2;
              int total=total2-total1;
              total/=2;
              total+=total1;
              int h=total/60;
              int m=total%60;
               StringBuilder build=new StringBuilder();
              if(h>9){
                  build.append(h+":");
                  if(m>9){
                      build.append(m);
                  }
                  else{
                      build.append("0"+m);
                  }
              }
              else{
                  build.append("0"+h+":");
                  if(m>9){
                      build.append(m);
                  }
                  else{
                      build.append("0"+m);
                  }
              }
              System.out.println(build.toString());
         }

     public static class Algo{
    public void merge(int arr[], int l, int m, int r){
        int n1 = m - l + 1;
        int n2 = r - m;

        int L[] = new int [n1];
        int R[] = new int [n2];

        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        int i = 0, j = 0;

        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    public void sort(int arr[], int l, int r){
        if (l < r)
        {
            int m = (l+r)/2;

            sort(arr, l, m);
            sort(arr , m+1, r);

            merge(arr, l, m, r);
        }
    }
    public static ArrayList<Integer> sieve(int n){
        long sqr=(long) Math.sqrt(n);
        boolean[] isPrime=new boolean[n+1];
        for(int i=0;i<=n;i++)
            isPrime[i]=true;
        for(int i=2;i<=sqr;i++){
            if(isPrime[i]){
                for(int p=i*i;p<=n;p+=i)
                    isPrime[p]=false;
            }
        }
        ArrayList<Integer> list=new ArrayList<Integer>();
        for(int i=0;i<=n;i++)
            if(isPrime[i])
                list.add(i);
        list.remove(0);
        list.remove(0);
        return list;
    }
    public static boolean isPrime(long n){
        boolean res=true;
        List l =sieve((int) Math.sqrt(n));
        for(int i=0;i<l.size();i++){
            int curPrime=(int) l.get(i);
            if(n%curPrime==0){
            res=false;
            break;
            }
        }
        return res;
    }
    public static ArrayList factorizatin(int n){
        if(isPrime(n)){
            System.out.println(-1);
            return null;
        }else{
        Iterator ptr =sieve((int) Math.sqrt(n)).iterator();
        ArrayList<Integer> list=new ArrayList<Integer>();
        if(ptr.hasNext()){
        int cur=(int) ptr.next();
           // System.out.println(cur);
         while(n!=1){
            while(n%cur==0){
                list.add(cur);
                n/=cur;
            }
            if(ptr.hasNext())
            cur=(int) ptr.next();
             //System.out.println(cur);
        }
        }
        if(n>2)
            list.add(n);
        return list;
        }
    }
    public static long gcd(long a,long b){
        if(b==0)
            return a;
        else
            return gcd(b,a%b);
    }
    public static long lcm(long a,long b){
        long ab=a*b;
        long gcd=gcd(a,b);
        return ab/gcd;
    }
    public static int bs(int[]z,int k){
             int res=0;
             int l=0;
             int r=z.length-1;
             int mid=(l+r)/2;
             while(l<=r){

                 if(z[mid]==k){
                     res=1;
                     break;
                 }
                 if(z[mid]>k)
                     r=mid-1;
                 else
                     l=mid+1;
                 mid=(l+r)/2;
             }
             return res;
         }
     }
    private static class DS{
    private static class Stack {
    private int Size;
    Node top;
    Stack(){

    Size=0;
    top=null;
    }
    public int size(){
    return this.Size;
    }
    public void push(Object item){
    Node node=new Node();
    node.data=item;
    node.next=top;
    top=node;
    Size++;
    }
    public void pop(){
    if(top!=null)
        top=top.next;
    Size--;
    }
    public boolean isEmpty(){
    return top==null;
    }
    public Object getTop(){
    if(top!=null)
        return top.data;
    else
        return null;
    }
    public void display(){
    if(top!=null){
        Node temp=top;
    while(temp!=null){
        System.out.print(temp.data+" ");
        temp=temp.next;
    }
        System.out.println();
    }
    }
  private class Node {
  Object data;
  Node next;
  }
}
    private static class Scanner
    {
        BufferedReader br;
        StringTokenizer st;

        public Scanner()
        {
            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;
        }

        BigInteger nextBigInteger()
        {
            return new BigInteger(next());
        }

    }
     }
}/*


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

public class sol
{

    /********* SOLUTION STARTS HERE ************/
    static class graph{
        int n;
        ArrayList<Integer> adj[];
        int wt[];
        graph(int v){
            n = v;
            adj = new ArrayList[n];
            for (int i=0;i<n;++i){
                adj[i] = new ArrayList<Integer>();
                //adj[i].add(i);
            }
            wt = new int[n];
            for (int i=0;i<n;++i){
                wt[i] = 0;
            }
        }
        void addedge(int v,int u){
            adj[v].add(u);
            //adj[u].add(v);
        }
        void bfs(int v,boolean visited[]){
         // Mark the current node as visited and print it
            visited[v] = true;
            //System.out.print(v+" ");

            // Recur for all the vertices adjacent to this vertex
            Iterator<Integer> i = adj[v].listIterator();
            while (i.hasNext())
            {
                int n = i.next();
                if (!visited[n])
                    bfs(n, visited);
            }
        }
    }
    private static void solve(FastScanner s1, PrintWriter out){
        int n=s1.nextInt();
        int m=s1.nextInt();
        String s = s1.nextLine();
        String ss = s1.nextLine();
        if (s[0] == '<'){
            if (s[n-1] == '>'){
                if (ss[n-1] == '^'){
                    if (ss[0] != ss[m-1]){
                        System.out.println("YES");
                    } else{
                        System.out.println("NO");
                    }
                } else {
                    System.out.println("NO");
                }
            } else {
                System.out.println("NO");
            }
        } else {
            if (s[n-1] == '<'){
                if (ss[0] == '^'){
                    if (ss[m-1] != ss[0]){
                        System.out.println("YES");
                    } else{
                        System.out.println("NO");
                    }
                } else {
                    System.out.println("NO");
                }
            } else {
                System.out.println("NO");
            }
        }
    }
    /********** TEMPLATE STARTS HERE ***********/

    public static void main(String []args) throws IOException {
    FastScanner in  = new FastScanner(System.in);
    PrintWriter out =
        new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    solve(in, out);
    in.close();
    out.close();
    }

    static class FastScanner{
    BufferedReader reader;
    StringTokenizer st;
    FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
    String next()
        {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
         st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
    String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
    int    nextInt()   {return Integer.parseInt(next());}
    long   nextLong()  {return Long.parseLong(next());}
    double nextDouble(){return Double.parseDouble(next());}
    char   nextChar()  {return next().charAt(0);}
    int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
    long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
    int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
    long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
    void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }

    /*********** TEMPLATE ENDS HERE *************/
}


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

public class City{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int hStreet = input.nextInt();
        int vStreet = input.nextInt();
        input.nextLine();

        char[] hStr = new char[hStreet];
        for(int i = 0; i < hStreet; i++)
        {
            hStr[i] = input.nextChar();
        }
        input.nextLine();

        char[] vStr = new char[vStreet];
        for(int i = 0; i < vStreet; i++)
        {
            vStr[i] = input.nextChar();
        }
        input.nextLine();

        boolean inOverOut = false, outOverin = false;

        //input is now dealt with, iterate through each input...
        for(int i = 0; i < hStreet; i++)
        {
            char h = hStr[i];
            for(int ii = 0; ii < vStreet; ii++)
            {
                char v = vStr[ii];
                int in = 0;
                int out = 0;

                //check for inward and outward edges...
                //above
                if(ii > 0)
                {
                    if(v == '^')
                    {
                        out++;
                    }
                    else
                    {
                        in++;
                    }
                }

                //below
                if(ii < vStreet-1)
                {
                    if(v == '^')
                    {
                        in++;
                    }
                    else
                    {
                        out++;
                    }
                }

                //left
                if(i > 0)
                {
                    if(h == '>')
                    {
                        in++;
                    }
                    else
                    {
                        out++;
                    }
                }

                //right
                if(i < hStreet-1)
                {
                    if(h == '>')
                    {
                        out++;
                    }
                    else
                    {
                        in++;
                    }
                }

                //assess what type of node this is...
                if(out == in+1)
                {
                    if(outOverin)
                    {
                        System.out.println("NO");
                        return;
                    }

                    outOverin = true;
                    continue;
                }

                if(in == out+1)
                {
                    if(inOverout)
                    {
                        System.out.println("NO");
                        return;
                    }

                    inOverout = true;
                    continue;
                }

                //special one-time cases accounted for, rest have to be =
                if(in == out)
                {
                    continue;
                }

                //freak situation, a lot more in than out, or vice versa
                System.out.println("NO");
                return;
            }
        }

        //we finished iterating over all nodes
        if(inOverout && outOverin)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class StronglyConnectedCity
{
	public static class Node
	{
        int degreeIn;
        int degreeOut;

        public Node()
        {
            degreeIn = 0;
            degreeOut = 0;
        }
    }

	public static class Edge
	{
		int destination;
		boolean used;

        public Edge(int dest)
        {
            destination = dest;
            used = false;
        }

        public int otherNode(int vertex)
        {
        	if (vertex == u)
        		return v;
        	else if (vertex == v)
        		return u;
        	else
        		throw new IllegalArgumentException("Invlaid edge");
        }
    }

	/*public static Stack<Integer> eulerianPath(List<Node> graph)
	{
		Stack<Integer> path = new Stack<Integer>();

		int oddDegrees = 0;
		int start = 0;
		for (int i = 0; i < graph.size(); i++)
		{
			if (graph.get(i).neighbors.size() % 2 != 0)
				oddDegrees++;
				start = i;
		}
		if (oddDegrees == 1 || oddDegrees > 2)
			return path;

		Queue<Edge>[] adj = (Queue<Edge>[]) new Queue[graph.size()];
		for (int i = 0; i < graph.size(); i++)
		{
			adj[i] = new LinkedList<Edge>();
		}

		for (int i = 0; i < graph.size(); i++)
		{
			for (Node next : graph.get(i).neighbors)
			{
				if (i < next.nodeNum)
				{
					Edge e = new Edge(i, next.nodeNum);
					adj[i].add(e);
					adj[next.nodeNum].add(e);
				}
			}
		}

		Stack<Integer> stack = new Stack<Integer>();
		stack.push(start);

		while (!stack.isEmpty())
		{
			int node = stack.pop();
			while (!adj[node].isEmpty())
			{
				Edge e = adj[node].poll();
				if (e.used)
					continue;
				e.used = true;
				stack.push(node);
				node = e.otherNode(node);
			}
			path.push(node);
		}

		return path;
	}*/

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		String horz = sc.nextLine();
		String vert = sc.nextLine();
		Node[][] nodes = new Node[n][m];
		for (int r = 0; r < n; r ++)
		{
			for (int c = 0; c < m; c++)
			{
			    nodes[r][c] = new Node();
			}
		}

		for (int i = 0; i < n; i++)
		{
			if (horz.charAt(i) == '>')
			{
			    for (int c = 0; c < m - 1; c++)
			    {
			        nodes[i][c].degreeOut++;
			        nodes[i][c + 1].degreeIn++;
			    }
			}
			else
			{
			    for (int c = m - 1; c > 0; c--)
			    {
			        nodes[i][c].degreeOut++;
			        nodes[i][c - 1].degreeIn++;
			    }
			}
		}

		for (int i = 0; i < m; i++)
		{
			if (vert.charAt(i) == 'v')
			{
			    for (int r = 0; r < n - 1; r++)
			    {
			        nodes[r][i].degreeOut++;
			        nodes[r + 1][i].degreeIn++;
			    }
			}
			else
			{
			    for (int r = n - 1; r > 0; r--)
			    {
			        nodes[r][i].degreeOut++;
			        nodes[r - 1][i].degreeIn++;
			    }
			}
		}

		for (int r = 0; r < n; r++)
		{
		    for (int c = 0; c < m; c++)
		    {
		        if (nodes[r][c].degreeIn == 0 || nodes[r][c].degreeOut == 0)
		        {
		            System.out.println("NO");
		            return;
		        }
		    }
		}
		System.out.println("YES");
	}
}


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

public class Main {

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

        // number of streets
        int horiStreets = s.nextInt();
        int vertStreets = s.nextInt();

        // street directions
        s.nextLine();
        String horizontal = s.nextLine();
        String vertical = s.nextLine();

        boolean strong = true;

        char yOrigin = horizontal.charAt(0);
        char xOrigin = vertical.charAt(0);
        char yMax = horizontal.charAt(horiStreets - 1);
        char xMax = vertical.charAt(vertStreets -1);

        if (yOrigin == '>' && xOrigin == '^')
            strong = false;
        if (yMax == '<' && xOrigin == '^')
            strong = false;
        if (yOrigin == '>' && xMax == 'v') {
            strong = false;
        if (yMax == '<' && xMax == 'v')
            strong = false;

        if (strong)
            System.out.print("YES");
        else
            System.out.print("NO");

        s.close();
    }
}


import java.util.*;

public class B{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n>=36){
			System.out.println(-1);
		}
		String nombre = "";
		for (int i=0;i<n;i+=2){
			nombre+="8";
		}
		if (nombre%2==1){
			nombre+="4";
		}
		System.out.println(nombre);
	}
}


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

public class AProsperousLot{

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

        if(k > 36)
            System.out.println(-1);
        if(k==0)
            System.out.println(1);
        if(k==1)
            System.out.println(4);
        int i;
        for( i=k;i>1;i-=2)
            System.out.print(8);
        if(i==1)
            System.out.println(4)
    }

}


//package con2;

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

public class B {

	public static void main(String[] args) {
		STDIN s= new STDIN();
		int n=s.nextInt();
		if(n%2==0){
			if(n/2<19){
				for(int i=0;i<(n)/2;i++){
					System.out.print("8");
				}
				System.exit(0);
			}else{
				System.out.println("-1");
				System.exit(0);
			}
		}else{
			if((n-1)/2<18){
				System.out.print("4");
				for(int i=0;i<(n-1)/2;i++){
					System.out.print("8");
				}
				System.exit(0);
			}else{
				System.out.println("-1");
				System.exit(0);
			}
		}
	}

}
//class STDIN {
	BufferedReader br;
	StringTokenizer st;

	public STDIN() {
		br = new BufferedReader(new InputStreamReader(System.in));
		st = null;
	}

	boolean hasNext() throws Exception {
		if (!st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.hasMoreTokens();
	}

	int nextInt()  {
		try{
		return Integer.parseInt(next());
		}catch(Exception e){
			System.out.print("error");
			return-1;

		}
	}

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

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

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

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


import java.io.*;
import java.util.*;
public class Main
{
     public static void main(String args[])
     {
          Scanner sc=new Scanner(System.in);
          int n=sc.nextInt();
          int x=Math.floor(n/2);
          int val=0;
          for(int i=0;i<x;i++)
          {
               val=val*10+8;
          }
          if(n%2==0)
          System.out.println(val);
          else
          System.out.println(val*10+9);
     }
}


public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println((n - 2) * (n - 2));
    }
}


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

public class Main {

	public static void main(String[] args)throws IOException {
		BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine().trim());
		System.out.println((n-2)*(n-2));
		}
	}
}


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

/**
 * Created by HARISH on 11/1/2015.
 */
public class TheMonster {
    public static void main(String[] args) throws IOException{
        BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
        long n;
         n = Integer.parseInt(kb.readLine());

            long ans = 0;
            ans += (n - 2);
            ans += 2 * (n - 3);
            if ((n - 3) * (n - 4) > 0) {
                ans += (n - 3) * (n - 4);
            }
            System.out.println(ans);
        }
    }
}


import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner SC = new Scanner(System.in);
        int n = SC.nextInt();
        int sum=n-2;
        for(int i=n-3; i>0; i--){
            sum+=2*i;
        }
        System.out.println(sum);
    }


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

public class TwoeightyfourA
{
    public static int totient(int num){ //euler's totient function calculator. returns totient
        int count=0;
        for(int a=1;a<num;a++){ //definition of totient: the amount of numbers less than num coprime to it
            if(GCD(num,a)==1){ //coprime
                count++;
            }
        }
        return(count);
    }
    public static int GCD(int a, int b){ //faster euclidean algorithm-see GCD for explanation
        int temp;
        if(a<b){
            temp=a;
            a=b;
            b=temp;
        }
        if(a%b==0){
            return(b);
        }
        return(GCD(a%b,b));
    }

    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int p = Integer.parseInt(input.next());
        int t = totient(p-1);
        int output = int t
    }

}


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt();
        int count = 0;
        for (int x = 2; x < p; x++) {
            int n = 1;
            int i = 2;
            boolean flag = false;
            for (; i < p; i++) {
                n *= x;
                n += 1;

                if (n % p == 0) {
                    if (i == p - 1) {
                        flag = true;
                    }

                    break;
                }
            }

            if (flag) {
                count++;
            }
        }
        System.out.println(count);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

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

    static class TaskA
    {
        private final static int MAX = 2000 + 1;
        private boolean isPrime = new boolean[MAX];
        private int primes = new int[303];

        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {

            Arrays.fill(isPrime, true);
            isPrime[0] = false;
            isPrime[1] = false;
            for (int i = 2; i * i < MAX; i++)
            {
                for (int j = i * i; j < MAX; j += i)
                {
                    isPrime[j] = false;
                }
            }

            for (int i = 0, j = 0; i < isPrime.length; i++)
            {
                if (isPrime[i])
                {
                    primes[j++] = i;
                }
            }
            int result[] = new int[MAX];
            for (int i = 0; i < result.length; i++)
            {
                if (isPrime[i])
                {
                    result[i] = count(i);
                }
            }

            int n = in.nextInt();
            out.println(result[n]);
        }

        public int count(int p)
        {
            int s = p - 1;
            int result = s;
            for (int i = 0; primes[i] <= s; i++)
            {
                if (s % primes[i] == 0)
                {
                    result = result * (primes[i] - 1) / primes[i];
                }
            }
            return result;
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }

    static class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

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

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

    }
}


public class Main  {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt();
        final BigInteger pp = new BigInteger("" + p);
        int ans = 0;
        for (int x = 1; x < p; x++) {
            boolean flag = true;
            BigInteger xx = new BigInteger("" + x);
            for (int j = 1; j <= p - 2 && flag; j++)
            {
            	if( (xx.modPow(new BigInteger("" + j), pp).longValue() - 1)%p == 0 )
                    flag = false;
            }
            if(flag && ( xx.modPow(new BigInteger("" + (p - 1)), pp).longValue() - 1 ) % p == 0)
                ++ans;
        }
        System.out.println(ans);
    }
}


import java.util.*;
public class vladik
{
    public static void main(String []args)
    {
        Scanner s=new Scanner(System.in);
        int a=s.newInt();
        int b=s.newInt();
        int t=0;
        while(a>=0&&b>=0)
        {
            t++;
            if(t%2!=0)
            a=a-t;
            else
            b=b-t;
        }
        if(a<0)
        System.out.println("Vladik");
        else
        System.out.println("Valera");
    }

}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution {
    public static void main(String[] args){
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String s=br.readLine();
        String ar[]=s.split(" ");
        int a=Integer.parseInt(ar[0]);
        int b=Integer.parseInt(ar[1]);
        if(a<=b){
            System.out.println("Valera");
        }else{
            System.out.println("Vladik");
        }
    }
}


import com.sun.org.apache.regexp.internal.RE;

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

public class Main {
    /*
     * Complete the function below.
    */
    public static void main(String[] args) throws IOException {
        //Scanner in = new Scanner(System.in);
//        System.setIn(new FileInputStream(new File("input.txt")));
//        System.setOut(new PrintStream(new File("filename1.txt")));
        Reader.init(System.in);
        Print print = new Print();

        int a = Reader.nextInt();
        int b = Reader.nextInt();

        int mA = 0;
        int mB = 0;

        int count = 0;

        while (a>=0 && b>=0) {
            if (count%2 == 0) {
                b-=count;
            } else {
                a-=count;
            }
            if (a<0){
                print.println("Vladik");
                print.close();
                break;
            } else if (b<0) {
                print.println("Valera");
                print.close();
                break;
            }
            count++;
        }

        //int m = Reader.nextInt();

//        for (int i = 0 ; i<n; ++i) {
//            int r = Reader.nextInt();
//            int c = Reader.nextInt();
//            int t1, t2, ans;
//            ArrayList<String> in1 = new ArrayList<>();
//            ArrayList<String> in2 = new ArrayList<>();
//            //char in[][] = new char[r+1][c+1];
//            for (int j = 0 ; j < r; ++j){
//                in1.add(Reader.next());
//            }
//            char ans1 = '\n';
//            for (int j = 0; j < in1.size(); ++j){
//                String temp = in1.get(j);
//                for (int k = 0; k < temp.length(); ++k){
//                    if (temp.charAt(k) != '?'){
//                        ans1 = temp.charAt(k);
//                    }
//                }
//            }
//            for (int j = 0; j < in1.size(); ++j){
//                String temp = in1.get(j);
//                char[] tempArray = temp.toCharArray();
//                for (int k = 0; k < temp.length(); ++k){
//                    if (tempArray[k] == '?'){
//                        tempArray[k] = ans1;
//                    }
//                }
//                in2.add(String.valueOf(tempArray));
//            }
//
//
//            print.print("Case #");
//            print.print(i+1);
//            print.println(":");
//
//            for (int j = 0; j < r; ++j){
//                print.println(in2.get(j));
//            }
//
////            if (m%p == 0) {
////                t1 = m/p;
////            } else {
////                t1 = m/p + 1;
////            }
//
////            if (t1 % 2 == 0) {
////                ans1 = t1/2;
////                ans2 = ans1 - 1;
////            } else {
////                ans1 = t1/2;
////                ans2 = ans1;
////            }
////            print.print(input);
////            print.print(" ");
////            print.println(k);
//        }

    }

    /** Class for buffered reading int and double values */
    static class ReaderMain {
        private static BufferedReader reader;
        private static StringTokenizer tokenizer;

        /** call this method to initialize reader for InputStream */
        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input) );
            tokenizer = new StringTokenizer("");
        }

        /** get next word */
        static String next() throws IOException {
            while (! tokenizer.hasMoreTokens() ) {
                //TODO add check for eof if necessary
                tokenizer = new StringTokenizer(
                        reader.readLine() );
            }
            return tokenizer.nextToken();
        }

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

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

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

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

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

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

        static char[] nextCharArray() throws IOException {
            return nextLine().toCharArray();
        }
    }

    class PrintMain {

        private final BufferedWriter bw;
        PrintMain() {
            this.bw=new BufferedWriter(new OutputStreamWriter(System.out));
        }
        void print(Object object)throws IOException {
            bw.append("").append(String.valueOf(object));
        }
        void println(Object object)throws IOException {
            print(object);
            bw.append("\n");
        }
        void close()throws IOException {
            bw.close();
        }
    }

}


import java.util.*;
import java.lang.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int Vla=sc.nextInt();
        int val=sc.nextInt();
        int i=1;int j=2;
        String result="";
        while(vla>0&&val>0){
            if(vla-i<0) {result="Vladik";break;}
            if(vla-i>0){vla=vla-i;i+=2;}
            if(val-j<0){result="Valera";break;}
            if(val-j>0){val=val-j;j=j+2;}
        }
        System.out.println(result);
    }
}


//package com.company;

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

public class Main {
    public static void main(String[] args) throws Exception {
        MyScanner sc = new MyScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        long start = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);

        long end = System.currentTimeMillis();
//        pw.println("Used time " + (end - start) + "ms.");
        pw.close();
    }

    public static class Task {

        public void solve(MyScanner sc, PrintWriter pw) throws IOException {
            int[] isprime = new int[1000010];
            Arrays.fill(isprime, 1);
            for (int i = 2; i < Math.sqrt(isprime.length) + 1; i++) {
                if (isprime[i] == 1) {
                    for (long j = i + i; j < isprime.length; j+=i) {
                        if (j > isprime.length) continue;
                        isprime[(int)j] = i;
                    }
                }
            }
            int a = sc.nextInt();
            if (isprime[a] == 1) {
                pw.println(a);
                return;
            }
            int bigfact = isprime[a];
            int mini = Integer.MAX_VALUE;
            for (int i = a - bigfact + 1; i <= a - 1; i++) {
                int m = isprime[i];
                int low = i - m + 1;
                mini = Math.min(low, mini);
            }
            pw.println(mini);

        }

    }

    static class MyScanner {
        StringTokenizer st;
        BufferedReader br;

        public MyScanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public MyScanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

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

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

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

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

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

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


import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x2 = sc.nextInt();
		int rootx2 = (int)Math.sqrt((double)x2)+1;
		boolean[] isPrime = new boolean[x2+1];
		isPrime[2] = true;
		for(int i=3;i<=x2;i+=2) isPrime[i] = true;
		for(int i=3;i<=rootx2;i+=2){
			if(isPrime[i]){
				for(int j=i*i;j<=x2;j+=2*i) isPrime[j] = false;
			}
		}

		int p2 = maxPrime(x2,isPrime);
		int x0 = Integer.MAX_VALUE;

		for(int x1=x2-p2+1;x1<=x2;++x1){
			if(!isPrime[x1]){
				int p1 = maxPrime(x1);
				x0 = Math.min(x0, p1*((x1/p1)-1)+1);
			}
		}

		if(x0!=Integer.MAX_VALUE) System.out.println(x0);
		else System.out.println(x2-p2+1);
		return;
	}

	public static int maxPrime(int x){ //最大素因数
		if(valid[x]) return x;
		int max = 0;
		int num = x;
		while(num%2==0){num/=2; max=2;}
		while(num%3==0){num/=3; max=3;}
		while(num%5==0){num/=5; max=5;}

		int count = 0;
		while(true){
			count++;
			int prime = 6*count + 1;
			if(prime*prime>num) break;
			if(num%prime==0){
				num /= prime;
				max = prime;
			}
			prime += 4;
			if(prime*prime>num) break;
			if(num%prime==0){
				num /= prime;
				max = prime;
			}
		}

		return Math.max(max, num);
	}
}


import java.util.Scanner;

public class P4 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        int[] f = new int[1000010];
        int x0 = n;

        for (int i = 2; i <= n; i++) {
            if (f[i] == 0) {
                for (int j = i + i; j <= n; j += i)
                    f[j] = i;
            }
        }
        int min = 10000000;
        for (int i = n - f[n] + 1; i <= n; i++){
            min = Math.min(min, i - f[i] + 1);
        }
        System.out.println(min);
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class A_Eound_470_Div1 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int x = in.nextInt();
        boolean[]p = new boolean[1000001];
        TreeSet<Integer> list = new TreeSet();
        for(int i = 2; i < p.length; i++){
            if(!p[i]){
                list.add(i);
                for(int j = i + i; j < p.length; j += i){
                    p[j] = true;
                }
            }
        }
        if(list.contains(x)){
            out.println(x);
        }else{
            out.println(cal(x, list));
        }
        out.close();
    }
    static int cal(int x, TreeSet<Integer> p){
        int re = x;
        Integer v = p.loww
        for(int i : p){
            if(i > x){
                break;
            }
            if(x % i == 0){
                int left = x/i;
                for(int j = (left - 1)*i + 1; j < x; j++){
                    if(p.contains(j)){
                        re = Integer.min(re, j);
                        continue;
                    }
                    for(int k : p){
                        if(k > j){
                            break;
                        }
                        if(j% k == 0){
                            int other = j / k;
                            for(int h = (other - 1)*k + 1; h < j; h++){
                                if(!p.contains(h)){
                                   // System.out.println(h + " " + j + " " + k + " " + i);
                                    re = Integer.min(re, h);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        return re;
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

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

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	public static void main(String[] args) throws IOException
	{
		int n =ni();
		long a=1,b=1;
		long ans=0;
		for(i=1;i<=n;i++){
			a=(27*a)%mod;
			b=(7*b)%mod;
			ans=(a-b+d)%mod;
		}
		System.out.println(ans);
	}
	static int bsl(int arr[],int data,int start,int end){
		int mid=start+(end-start)/2;
		if(arr[mid]==data)
			return mid;
		if(end-start==1)
			return mid;
		else if(data > arr[mid])
			return bsl(arr,data,mid,end);
		else
			return bsl(arr,data,start,mid);
	}
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	static StringBuilder ans=new StringBuilder();
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static Random rn=new Random();
	static void pd(){if(debug)ans.append("hola");}
	static void pd(Object a){if(debug)ans.append(a+"\n");}
	static void pr(Object a){ans.append(a+"\n");}
	static void pr(){ans.append("\n");}
	static void p(Object a){ans.append(a);}
	static void sop(Object a){System.out.println(a);}
	static int ni(){return in.nextInt();}
	static int[] nia(int n){int a[]=new int[n];for(int i=0; i<n; i++)a[i]=ni();return a;}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static long nl(){return in.nextLong();}
	static String ns(){return in.next();}
	static double nd(){return in.nextDouble();}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
	static class dyns
	{
		dyns(long le,long ri)
		{
			lb=le;
			rb=ri;
		}
		dyns l,r;
		long val,lb,rb;
		void set(long te)
		{
			val++;
			if(lb!=te||rb!=te)
			{
				if((lb+rb)/2>=te)
				{
					if(l==null)
						l=new dyns(lb, (lb+rb)/2);
					l.set(te);
				}
				else
				{
					if(r==null)
						r=new dyns(((lb+rb)/2)+1,rb);
					r.set(te);
				}
			}
		}
		void reset(long a)
		{
			val--;
			if(val==0)
			{
				l=null;
				r=null;
				return;
			}
			if(lb!=a||rb!=a)
			{
				if((lb+rb)/2>=a)
					l.reset(a);
				else
					r.reset(a);
			}
		}
		long count(long le, long ri)
		{
			if(le<=lb&&ri>=rb)
				return val;
			if(le>rb)
				return 0;
			if(ri<lb)
				return 0;
			int a=0;
			if(l!=null)
				a+=l.count(le,ri);
			if(r!=null)
				a+=r.count(le,ri);
			return a;
		}
	}
}


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

public class Sample {
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter pw = new PrintWriter(System.out);
    private static StringBuffer ans = new StringBuffer();

    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        BigInteger bg = BigInteger.TWO.add(BigInteger.ONE);
        BigInteger seven = new BigInteger("7");
        seven = seven.pow(n);
        bg = bg.pow(3 * n);
        bg = bg.subtract(seven);
        bg = bg.mod(BigInteger.valueOf(1000000007L));
        ans.append(bg);
        pw.print(ans);
        sc.close();
        pw.close();
    }

}

class Scanner {
    private final BufferedReader br;
    private StringTokenizer st;

    public Scanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(in));
        st = new StringTokenizer("");
    }

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

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

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

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

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

    public void close() throws IOException {
        br.close();
    }
}

class PrintWriter {
    private final BufferedOutputStream pw;

    public PrintWriter(OutputStream out) {
        pw = new BufferedOutputStream(out);
    }

    public void print(Object o) throws IOException {
        pw.write(o.toString().getBytes());
        pw.flush();
    }

    public void println(Object o) throws IOException {
        print(o + "\n");
    }

    public void close() throws IOException {
        pw.close();
    }
}


*Author LAVLESH*/
import java.util.Scanner;

public class solution {
	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		long count=(long)(Math.pow(3,3*n)-Math.pow(7,n));

		System.out.println(count%1000000007);
	}
}


public class KolyaAndTanya {
    private static final int MOD = 1000000007;
    public static int getOutput(int number) {
        int num = 1;
        int result = 0;
        while (number > 0) {
            result = (result * 27 + 20 * num) % MOD;
            num = num * 7;
            number--;
        }
        return result;
    }
    public static void main(String[] args) {
        try {
            InputStreamReader in = new InputStreamReader(System.in);
            BufferedReader input = new BufferedReader(in);
            int lineNum = 0;
            String str;
            int number = 0;
            while (lineNum < 1 && (str = input.readLine()) != null) {
                number = Integer.parseInt(str);
                lineNum++;
            }
            System.out.println(getOutput(number));
        } catch (IOException io) {
            io.printStackTrace();
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CF1528B_KaviOnPairingDuty {

	static class IO {
		private boolean type;
		private BufferedReader br;
		private StringTokenizer st;
		private PrintWriter pw;

		public IO() {
			br = new BufferedReader(new InputStreamReader(System.in));
			type = false;
		}

		public IO(String file) {
			type = true;
			try {
				br = new BufferedReader(new FileReader(file + ".in"));
				pw = new PrintWriter(new BufferedWriter(new FileWriter(file + ".out")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		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;
		}

		void print(Object b) {
			if (type)
				pw.print(b);
			else
				System.out.print(b);
		}

		void println(Object b) {
			if (type)
				pw.println(b);
			else
				System.out.println(b);
		}

		void println() {
			if (type)
				pw.println();
			else
				System.out.println();
		}

		void close() {
			if (type)
				try {
					br.close();
					pw.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}

		void fill(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				arr[i] = nextInt();
			}
		}

		void fill(int[] arr, int add) {
			for (int i = 0; i < arr.length; i++) {
				arr[i] = nextInt() + add;
			}
		}

		void fill(int[][] arr) {
			for (int[] a : arr)
				fill(a);
		}

	}

	static int countDivisors(int n) {
		int cnt = 0;
		for (int i = 1; i <= Math.sqrt(n); i++) {
			if (n % i == 0) {
				if (n / i == i)
					cnt++;
				else
					cnt = cnt + 2;
			}
		}
		return cnt;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		IO io = new IO();
		int n = io.nextInt();
		int[] dp = new int[n + 1];
		dp[1] = 1;
		int add = dp[1];
		for (int i = 2; i <= n; i++) {
			dp[i] = (add + countDivisors(i)) % 998244353;
			add += dp[i];
			add %= 998244353;
		}
		io.println(dp[n]);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;

public class Main{
	public static StringTokenizer st=new StringTokenizer("");
	public static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	public static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out));
	public static String nextstr() throws IOException {
		while (!st.hasMoreTokens())
			st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	public static int nextint() throws NumberFormatException, IOException {
		return Integer.parseInt(nextstr());
	}
	public static double nextdb() throws NumberFormatException, IOException {
		return Double.parseDouble(nextstr());
	}
	public static long nextlong() throws NumberFormatException, IOException {
		return Long.parseLong(nextstr());
	}
	public static void printf(String format,Object... args) {
		pw.printf(format, args);
		pw.flush();
	}
	public static void debug(String out) {
		System.out.println(out);
	}

	public static final int maxn=(int)1e6+5;
	public static final int inf=0x3f3f3f3f;
	public static final long mod=998244353;

	public static long d[]=new long[maxn];

	public static long dfs(int n) {
		if (d[n]!=-1) return d[n];
		if (n==1) {
			d[1]=1;
			return 1;
		}
		d[n]=0;
		for (int i=1;i*i<=n;i++)
			if (n%i==0) {
				if (i*i==n)
					d[n]+=1;
				else d[n]+=2;
			}

		for (int i=1;i<n;i++)
			d[n]=(d[n]+dfs(i))%mod;
		return d[n];
	}
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n=nextint();
		Arrays.fill(d, -1);
		printf("%d",dfs(n));
	}//end
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class DKaviOnPairingDuty {
        static int divdp;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            long[] dp = new long[n + 1];
            dp[1] = 1;
            long sum = 1;
            divdp = new int[n + 1];
            divdp[1] = 1;
            Arrays.fill(divdp, 1);
            divisors(n);
            for (int i = 2; i <= n; i++) {
                dp[i] = sum;
                dp[i] = (dp[i] + divdp[i] + (i > n / 2 ? 1 : 0)) % 998244353;
                sum = (sum + dp[i]) % 998244353;
            }

            out.println(dp[n]);
        }

        public static void divisors(int x) {

            for (int i = 2; i <= x / 2; i++) {
                for (int j = 1; i * j <= x; j++) {
                    divdp[i * j]++;
                }
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }

    static class InputReader {
        BufferedReader reader;
        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.lang.*;
import java.io.*;

public final class Solution
{

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

        int sum =0;
        int t = s.nextInt();
        int M=998244353;
        int N=1000000+100;
        int dp=new int[N];
        int k = (int)(10*Math.random());
            int n = s.nextInt();
            for(int i=1;i<N;i++){
                for(int j=i;j<N;j+=i) {
                    dp[j]+=1;
                    if(dp[j]>=M) dp[j]-=M;
                    else if(dp[j]<0) dp[j]+=M;
                }
            }
            int sm=0;
            for(int i=1;i<=n;i++){

                    dp[j]+=sm;
                    if(dp[j]>=M) dp[j]-=M;
                    else if(dp[j]<0) dp[j]+=M;

                    sm+=dp[j];
                    if(sm[j]>=M) sm-=M;
                    else if(sm<0) sm+=M;
            }
            System.out.println(dp[n]);
    }

}


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

public class forces {

    static int a[][]= new int[5][5];
    static int midr = 3;
    static int midc = 3;

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

        // String ip[] = br.readLine().trim().split("\\s+");

        // int n = Integer.parseInt(ip[0]);
        // int m = Integer.parseInt(ip[1]);

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

       if(n>2){
           System.out.println(n-2);
       }

       else{
           Systen.out.println(n+2);
       }

	}

    public static String fun(String s){

        return "";
    }

}


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

import java.io.*;
import java.util.*;
public class S {
	public static void main (String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		Systen.out.println(n+2);
	}
}


/*
 * 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 javaapplication7;

import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author fatsu
 */
public class JavaApplication7 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //Random rand = new Random();
        Scanner reader = new Scanner(System.in);
        //int reader = rand.nextInt(999) + 1;

//        System.out.println(reader);

        int result;

        if(reader == 1){
            result = 5;
        } else if(reader == 2){
            result = 4;
        } else if(reader % 2 == 1){
            result = 3;
        } else {
            result = reader + 2;
        }

//        System.out.println(result);
//        System.out.println(reader*result + 1);

        System.out.print(result);
    }

}


import java.util.Scanner;
public class A{
       public static void main(String args[]){
              Scanner sc = new Scanner(System.in);
             int t ,n;

                    n=sc.nextInt();
                    if(n%2!=0)
                    {
                           if(n==1)
                                   System.out.println((3);
                            else
                                   System.out.println(1);
                    }
                    else{
                           for(int i=1;i<1000;i++){
                                  if(((n*i+1)%3==0 &&(n*i+1)!=3)||((n*i+1)%5==0 &&(n*i+1)!=5)||((n*i+1)%7==0 &&(n*i+1)!=7)){
                                         System.out.println(i);
                                         break;
                                  }

                           }
                    }

       }
}