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.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author gaidash
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            final int SIZE = 256;
            final int UNDEF = -1;

            int nPixels = in.nextInt();
            int groupSize = in.nextInt();
            int[] a = in.nextIntArray(nPixels);
            boolean[] exists = new boolean[SIZE];
            int[] left = new int[SIZE];
            int[] right = new int[SIZE];
            int[] ret = new int[nPixels];
            Arrays.fill(ret, UNDEF);

            for (int i = 0; i < nPixels; i++) {
                for (int p = 0; p < SIZE; p++) {
                    if (exists[p] && left[p] <= a[i] && a[i] <= right[p]) {
                        ret[i] = left[p];
                        left[a[i]] = left[p];
                        right[a[i]] = right[p];
                        break;
                    }
                }
                if (ret[i] == UNDEF) {
                    int l = Math.max(a[i] - groupSize + 1, 0);
                    int r = l + groupSize - 1;
                    for (int p = a[i] - 1; p >= 0; p--) {
                        if (exists[p]) {
                            if (p >= l) {
                                int d = p - l;
                                l = p + 1;
                                r += d + 1;
                            }
                            if (right[p] >= l) {
                                right[p] = l - 1;
                            }
                        }
                    }
                    for (int p = a[i] + 1; p < SIZE; p++) {
                        if (exists[p] && left[p] <= r) {
                            r = left[p] - 1;
                        }
                    }
                    left[a[i]] = l;
                    right[a[i]] = r;
                    ret[i] = l;
                }
                exists[a[i]] = true;
            }
//        for (int p : a) {
//            System.out.println("Segment for pixel " + p + " = " + "(" + left[p] + " , " + right[p] + ")");
//        }

            out.print(ret);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }

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

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

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

        public int 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 int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

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

        }

    }
}


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

public class Codeforces913F {
	public static void main(String[] args) throws IOException {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int a = input.nextInt();
		int b = input.nextInt();
		input.close();
		final int mod = 998244353;

		int frac = multiply(a, inverse(b, mod), mod);
		int reverse = (mod+1-frac)%mod;

		int[] fracpower = new int[n+1];
		int[] reversepower = new int[n+1];
		fracpower[0] = 1;
		reversepower[0] = 1;
		for (int i = 1; i <= n; i++) {
			fracpower[i] = multiply(fracpower[i-1], frac, mod);
			reversepower[i] = multiply(reversepower[i-1], reverse, mod);
		}

		int[][] dp1 = new int[n+1][n+1];
		dp1[2][1] = 1;
		for (int i = 3; i <= n; i++) {
			for (int j = 1; j < i; j++) {
				if (j == 1) {
					dp1[i][j] = fracpower[i-1];
				}
				else {
					dp1[i][j] = multiply(dp1[i-1][j-1], fracpower[i-j], mod);
				}
				if (j == i-1) {
					dp1[i][j] += reversepower[i-1];
					dp1[i][j] %= mod;
				}
				else {
					dp1[i][j] += multiply(dp1[i-1][j], reversepower[j], mod);
					dp1[i][j] %= mod;
				}
			}
		}

		int[][] dp2 = new int[n+1][n+1];
		dp2[1][1] = 1;
		dp2[2][1] = 1;
		dp2[2][2] = 0;
		for (int i = 3; i <= n; i++) {
			int val = 0;
			for (int j = 1; j < i; j++) {
				dp2[i][j] = multiply(dp2[j][j], dp1[i][j], mod);
				val += dp2[i][j];
				val %= mod;
			}
			dp2[i][i] = (mod+1-val)%mod;
		}

		/*for (int i = 2; i <= n; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(dp2[i][j] + " ");
			}
			System.out.println();
		}*/

		int[] EV = new int[n+1];
		EV[1] = 0;
		EV[2] = 1;
		for (int i = 3; i <= n; i++) {
			int val = 0;
			for (int j = 1; j < i; j++) {
				int r = j*(i-j) + (j*(j-1))/2 + EV[i-j] + EV[j];
				r %= mod;
				val += multiply(dp2[i][j], r, mod);
				val %= mod;
			}
			val += multiply((i*(i-1))/2, dp2[i][i], mod);
			val %= mod;

			int s = (mod+1-dp2[i][i])%mod;
			EV[i] = multiply(val, inverse(s, mod), mod);
		}

		System.out.println(EV[n]);
	}

	public static int multiply(int a, int b, int mod) {
		long x = (long)a*(long)b;
		return (int) (x%mod);
	}

	public static int inverse (int a, int n) {
		int m = n;
		int r1 = 1;
		int r2 = 0;
		int r3 = 0;
		int r4 = 1;
		while ((a > 0) && (n > 0)) {
			if (n >= a) {
				r3 -= r1*(n/a);
				r4 -= r2*(n/a);
				n = n%a;
			}
			else {
				int tmp = a;
				a = n;
				n = tmp;
				tmp = r1;
				r1 = r3;
				r3 = tmp;
				tmp = r2;
				r2 = r4;
				r4 = tmp;
			}
		}
		if (a == 0) {
			if (r3 >= 0)
				return (r3%m);
			else
				return (m+(r3%m));
		}
		else {
			if (r1 >= 0)
				return (r1%m);
			else
				return (m+(r1%m));
		}

	}
}


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

public class java2 {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);
        int n=r.nextInt();
        int []l=new int[1005];
        int []ri=new int[1005];
        int []candy=new int[1005];
        for(int i=1;i<=n;++i)
        {
            l[i]=r.nextInt();
        }
        for(int i=1;i<=n;++i)
        {
            ri[i]=r.nextInt();
        }
        for(int i=1;i<=n;++i)
        {
            if(l[i]>i-1||ri[i]>n-i)
            {
                System.out.println("NO");
                System.exit(0);
            }
            candy[i]=n-l[i]-ri[i];
        }
        for(int i=1;i<=n;++i)
        {
            int left=0,right=0;
            for(int j=1;j<=i-1;++j)
            {
                if(candy[j]>candy[i])
                {
                    ++left;
                }
            }
            for(int j=i+1;j<=n;++j)
            {
                if(candy[j]>candy[i])
                {
                    ++right;
                }
            }
            if(left!=l[i]||right!=ri[i])
            {
                System.out.println("NO");
                System.exit(0);
            }
        }
        System.out.println("YES");
        for(int i=1;i<=n;++i)
        {
            System.out.print(candy[i]+" ");
        }
    }
}


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

public class Solution{

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    public static void main(String args[] ) {

        FastReader sc = new FastReader();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[105];

        for(int i=0;i<m;i++){
            int a = sc.nextInt();
            arr[a]++;
        }

        for(int i=1;i<=1000;i++){
            int sum=0;

            for(int a:arr){
                if(a!=0){
                    sum+=(a/i);
                }
            }

            if(sum<n){
                System.out.println(i-1);
                return;
            }

        }
    }

}


//package codeforces;
import java.util.Scanner;
public class ex5 {
public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	String S [] = new String[3];

	int m=0,s=0,p=0;
	int temp=0;

	for (int i = 0; i < S.length; i++) {
		S[i]=scan.next();
		if(S[i].indexOf('m')!=-1) m++;
		if(S[i].indexOf('s')!=-1) s++;
		if(S[i].indexOf('p')!=-1) p++;
	}

	int n1 = Integer.parseInt(S[0].substring(0,1));
	int n2 = Integer.parseInt(S[1].substring(0,1));
	int n3 = Integer.parseInt(S[2].substring(0,1));

	    int d3 = Math.abs(n1-n2);
		int d4 = Math.abs(n1-n3);
		int d5 = Math.abs(n2-n3);

	if(m==3||s==3||p==3) {

		    if(d3==1&d5==1&d4==2||d3==1&d4==1&d5==2||d5==1&d4==1&d3==2)
			System.out.println(0);
		else
		    if(d3==0&d4==0) System.out.println(0);
		else
			if(d3<d5&d3<d4) {
			    if(d3==1||d3==2||d3==0) System.out.println(1);
		        else                 System.out.println(2);
			    }
			else if (d5<d4&d5<d3){
				 if(d5==1||d5==2||d5==0) System.out.println(1);
					else                 System.out.println(2);
			}
			else if(d4<d5&d4<d3) {
				if(d4==1||d4==2||d4==0) System.out.println(1);
				else                 System.out.println(2);
			}
			else if(d3==2&d5==2||d4==2&d5==2||d3==2&d4==2||d3==1&d5==1||d4==1&d5==1||d3==2&d4==1)
				System.out.println(1);
			else System.out.println(2);

	}

	if(m==2||s==2||p==2) {

		char c1 = S[0].charAt(1);
		char c2 = S[1].charAt(1);
		char c3 = S[2].charAt(1);

		if(c1==c2) {
			if(n1==n2) System.out.println(1);
			else if(d3==1||d3==2) System.out.println(1);
			else System.out.println(2);
		}
		if(c1==c3) {
			if(n1==n3) System.out.println(1);
			else if(d4==1||d4==2) System.out.println(1);
			else System.out.println(2);
		}
		if(c2==c3) {
			if(n2==n3) System.out.println(1);
			else if(d5==1||d5==2) System.out.println(1);
			else System.out.println(2);
		}
	}

	if(m==1&s==1&p==1) System.out.println(2);

}
}


import java.io.PrintWriter;

import java.util.*;
import java.util.Arrays ;
import java .lang.String.* ;
import java .lang.StringBuilder ;

public class Test{
    static int pos = 0 ;
    static int  arr[] ;
  static LinkedList l1 = new  LinkedList() ;
static void find(int p ,char[]x,int put[],String s){
    int c= 0 ;
    for (int i = 0; i < s.length(); i++) {
        if(x[p]==s.charAt(i)){
        c++ ; }
    }
    put[p] = c ;
}
static int mode(int m ,int[]x ){
    int temp = 0 ;
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ;
           /// break ;
             return m-temp ;

        }
    }
     return m-temp ;
}
static int mode2(int m ,int[]x ){
    int temp = 0 ;

    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ;
           /// break ;
             return x[i] ;

        }
    }
     return 0 ;
}
static int find(int x[],int temp){
    int j = 0 ;
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]==temp) return j+1 ;
        j++ ;
    }
    return -1 ;
}
static String ch(long[]x,long b){
    for (int i = 0; i < x.length; i++) {
        if(x[i]==b)return "YES" ;
    }
    return "NO" ;
}

    public static void main(String[] args)  {

        Scanner in = new Scanner(System.in) ;
        PrintWriter pw = new PrintWriter(System.out);
     int k=in.nextInt(), n=in.nextInt(), s=in.nextInt(), p=in.nextInt() ;
     int paper =n/s;
     if(n%s!=0) paper++ ;
     paper*=k ;
     int fin = paper/p ;
     if(paper%p!=0) fin++ ;
        System.out.println( fin );

 }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class loser
{
    static class InputReader {
        public BufferedReader br;
        public StringTokenizer token;
        public InputReader(InputStream stream)
        {
            br=new BufferedReader(new InputStreamReader(stream),32768);
            token=null;
        }

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

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

        public long nextLong()
        {
            return Long.parseLong(next());
        }
    }
    static class card{
        long a;
        int i;
        public card(long a,int i)
        {
            this.a=a;
            this.i=i;
        }
    }
    static class sort implements Comparator<pair>
    {
        public int compare(pair o1,pair o2)
        {
            if(o1.a!=o2.a)
                return (int)(o1.a-o2.a);
            else
                return (int)(o1.b-o2.b);
        }
    }
    static void shuffle(long a[])
    {
        List<Long> l=new ArrayList<>();
        for(int i=0;i<a.length;i++)
            l.add(a[i]);
        Collections.shuffle(l);
        for(int i=0;i<a.length;i++)
            a[i]=l.get(i);
    }

    /*static long gcd(long a,long b)
    {
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
    }*/
    /*static boolean valid(int i,int j)
    {
    if(i<4 && i>=0 && j<4 && j>=0)
    return true;
    else
    return false;
    }*/
    static class pair{
        int a,b;
        public pair(int a,int b)
        {
            this.a=a;
            this.b=b;
        }
    }
    public  static void main(String[] args)
    {
        InputReader sc=new InputReader(System.in);
        int k=sc.nextInt();
        int n=sc.nextInt();
        int s=sc.nextInt();
        int p=sc.nextInt();
        long d=(long)Math.ceil((double)n/s);
        if(d==0)
        d=1;
        d=k*d;
        long ans=(long)Math.ceil((double)d/p);
        System.out.println(ans);
    }
}


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

public class Lcm
{
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
long n=Long.parseLong(br.readLine());
if(n<=2)
pw.println(n);
else
{

 if(n%6==0)
{
 pw.println(((n-1)*(n-2)*(n-3)));
}
 else if(n%2==0)
{
  pw.println((n*(n-1)*(n-3)));
}
else
{
  pw.println((n*(n-1)*(n-2)));
}
}
pw.flush();
}
}


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

public class Task235A {

	public static void main(String... args) throws NumberFormatException,
			IOException {
		Solution.main(System.in, System.out);
	}

	static class Scanner {

		private final BufferedReader br;
		private String[] cache;
		private int cacheIndex;

		Scanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			cache = new String[0];
			cacheIndex = 0;
		}

		int nextInt() throws IOException {
			if (cacheIndex >= cache.length) {
				cache = br.readLine().split(" ");
				cacheIndex = 0;
			}
			return Integer.parseInt(cache[cacheIndex++]);
		}

		long nextLong() throws IOException {
			if (cacheIndex >= cache.length) {
				cache = br.readLine().split(" ");
				cacheIndex = 0;
			}
			return Long.parseLong(cache[cacheIndex++]);
		}

		String next() throws IOException {
			if (cacheIndex >= cache.length) {
				cache = br.readLine().split(" ");
				cacheIndex = 0;
			}
			return cache[cacheIndex++];
		}

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

	}

	static class Solution {

		public static void main(InputStream is, OutputStream os)
				throws NumberFormatException, IOException {
			PrintWriter pw = new PrintWriter(os);
			Scanner sc = new Scanner(is);

			long n = sc.nextInt();

			if (n < 3) {
				pw.println(n);
			} else {
				if (n % 2 != 0) {
					pw.println(n * (n - 1) * (n - 2));
				} else {
					if (n % 3 != 0) {
						pw.println(n * (n - 1) * (n - 3));
					} else {
						long cand1 = n * (n - 1) * (n - 2) / 2;
						long cand2 = (n - 1) * (n - 2) * (n - 3);
						pw.println(Math.max(cand1, cand2));
					}
				}
			}

			pw.flush();
			sc.close();
		}
	}

}


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

public class Main
{
    public static long gcd(long a, long b)
    {
        return b==0? a:gcd(b, a%b);
    }
    public static long lcm(long a, long b, long c)
    {
        long d=a/gcd(a, b)*b;
        return c/gcd(c, d)*d;
    }
    public static long max(long a, long b)
    {
        return a>b? a:b;
    }
    public static void main(String[] args)
    {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        long n=in.nextLong();
        if(n<=2)
            out.println(n);
        else
            out.println(max(lcm(n, n-1, n-2), max(lcm(n, n-1, n-3), lcm(n-1, n-2, n-3))));
        out.close();
    }
}

class InputReader
{
    BufferedReader buf;
    StringTokenizer tok;
    InputReader()
    {
        buf = new BufferedReader(new InputStreamReader(System.in));
    }
    boolean hasNext()
    {
        while(tok == null || !tok.hasMoreElements())
        {
            try
            {
                tok = new StringTokenizer(buf.readLine());
            }
            catch(Exception e)
            {
                return false;
            }
        }
        return true;
    }
    String next()
    {
        if(hasNext())
            return tok.nextToken();
        return null;
    }
    int nextInt()
    {
        return Integer.parseInt(next());
    }
    long nextLong()
    {
        return Long.parseLong(next());
    }
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
    BigInteger nextBigInteger()
    {
        return new BigInteger(next());
    }
    BigDecimal nextBigDecimal()
    {
        return new BigDecimal(next());
    }
}


import java.util.*;

/*Author LAVLESH*/
public class solution
{
	static long gcd(long a,long b){
		if(b==0) return a;
		else
			return gcd(b,a%b);

	}
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		long n=in.nextLong();
		long m1=0,m2=0;
		if(n<3)m1=n;
		else {
			if((n&1)==1){
				long lcm=n*(n-1)/gcd(n,n-1);
				m1=lcm*(n-2)/gcd(lcm,n-2);
			}
			else{
				long lcm=(n-1)*(n-2)/gcd(n-1,n-2);
				m1=lcm*(n-3)/gcd(lcm,n-3);

				 lcm=n*(n-1)/gcd(n,n-1);
				m2=lcm*(n-3)/gcd(lcm,n-3);
				m1 = Math.max(m1,m2);
			}
		}
		System.out.println(m1);

}}


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

public class Main {

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

    public static long LCM(long a, long b){
        return a*b / GCF(a, b);
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        if(n < 3) System.out.println(n);
        else{
            long t1 = LCM(n, n-1);
            long t2 = LCM(n-2, n-3);

            long l1 = LCM(t1, n-2);
            long l2 = LCM(t1, n-3);
            long l3 = LCM(n, t2);
            long l4 = LCM(n-1, t2);

        System.out.println(Math.max(l1, Math.max(l2, Math.max(l3, l4))));

        }

    }

}


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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 *
 * @author Sourav Kumar Paul
 */
public class A235 {
    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        long n = Long.parseLong(reader.readLine());
        //int gcd = gcd(924,923);
        //System.out.println(gcd);
       // System.out.println(gcd(923,461));
        if(n<=2)
            System.out.println(n);
        else if(n==3)
            System.out.println("6");

        else if(n % 2== 0)
       {
           if(n % 3 == 0)
           {
               System.out.println((n-3)*(n-1)*(n-2));
           }
           else

           System.out.println(n * (n-1) * (n-3) );
       }
        else
            System.out.println(n*(n-1)*(n-2));
    }
     private static int gcd(int i, int j) {
        int a = Math.min(i,j);
        int b = Math.max(i,j);
       while(a != 0)
       {
           int temp = b % a;
           b = a;
           a = temp;
       }
       return b;
    }
}


import java.math.BigInteger;
import java.util.Scanner;

public class A235 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n = scan.nextInt();
        BigInteger res = null;
        if (n >= 3) {
            if (n % 2 != 0) {
                res = BigInteger.valueOf(n * (n - 1) * (n - 2));
            } else if (n % 3 == 0) {
                res = BigInteger.valueOf((n - 1) * (n - 2) * (n - 3));
            } else {
                res = BigInteger.valueOf(n * (n - 1) * (n - 3));
            }
        } else {
            res = BigInteger.valueOf(n);
        }
        System.out.println(res);
    }
}


import java.util.Scanner;

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

        if (n <= 2)
            System.out.println(n);
        else if (n % 2 == 1)
            System.out.println(n * (n - 1) * (n - 2));
        else if (n % 3 == 0)
            System.out.println((n - 1) * (n - 2) * (n - 3));
        else
            System.out.println(n * (n - 1) * (n - 3));
    }
}


import java.util.Scanner;

public class A235 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        if (n == 1) {
            System.out.println(1);
            return;
        } else if (n == 2) {
            System.out.println(2);
            return;
        } else if (n == 3) {
            System.out.println(6);
            return;
        }

        if (n % 2 == 0) {
            if(n % 3 == 0)
                System.out.println((n - 1) * (n - 2) * (n - 3));
            else
                System.out.println((n - 1) * n * (n - 3));
        } else {
            System.out.println(n * (n - 1) * (n - 2));
        }
    }
}


import java.util.*;
public class Main
{
    public static void main(String[]args)
    {
        Scanner input=new Scanner (System.in);
        while(input.hasNext())
        {
            long n=input.nextLong();
            if(n==1||n==2)
                System.out.println(n);
            else if(n%2==1)
                System.out.println(n*(n-1)*(n-2));
            else
                if(n%3!=0)
                    System.out.println(Math.max(n*(n-1)*(n-3),n*(n-1)*(n-2)/2));
                else
                    System.out.println(Math.max(  Math.max(n*(n-1)*(n-3)/3,n*(n-1)*(n-2)/2) , Math.max((n-2)*(n-1)*(n-3),n*(n-2)*(n-3)/6) ));
        }
    }
}


import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        long num=in.nextLong();
        long lcm=1;
        if(num==2){
            System.out.println(2);
            System.exit(0);
        }//End if
        else if(num%2==0&&num%3!=0)
            lcm=(num)*(num-1)*(num-3);
        else if(num%2==0&&num%3==0)
            lcm=(num-1)*(num-2)*(num-3);
        else if(num%2!=0&&num>2)
            lcm=num*(num-1)*(num-2);
        System.out.println(lcm);
    }//End main()
}//End class


import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long num = input.nextLong();
        if(num==0){
            System.out.println(num);
        }else if(num==1||num==2){
            System.out.println(num);}
        else if(num%2==0&&num>2&&num%3!=0){
            System.out.println(num*(num-1)*(num-3));
        }
        else if(num%2==0&&num%3==0){
            System.out.println((num-1)*(num-2)*(num-3));
        }
        else{
        System.out.println(num*(num-1)*(num-2));}
    }

}


import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * Created by jizhe on 2016/1/29.
 */
public class LCMChallenge {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));

        long N = in.nextLong();
        if( N == 1 || N == 2 )
        {
            System.out.printf("%d\n", N);
            return;
        }

        if( (N&1) == 1 )
        {
            long lcm = N*(N-1)*(N-2);
            System.out.printf("%d\n", lcm);
        }
        else
        {
            if( N == 4 )
            {
                System.out.printf("12\n");
            }
            else
            {
                long lcm;
                if( N%3 == 0 )
                {
                    lcm = (N-1)*(N-2)*(N-3);
                }
                else
                {
                    lcm = N*(N-1)*(N-3);
                }

                System.out.printf("%d\n", lcm);
            }
        }
    }
}


import java.util.*;
public class maximus {
	static long GCD(long a,long b){
	if(b==0)return a;
	return GCD(b,a%b);
	}
public static void main(String [] args){
  Scanner in=new Scanner(System.in);
  long n=in.nextInt();
  if(n<=2){
  System.out.print(n);
  return;
  }
  if(n%2==1){
  System.out.print((n*(n-1)*(n-2)));
  return;
  }
  if(n%2==0 && n<=6){
  System.out.print(n*(n-1)*(n-2)/2);
  return;
  }
  long temp=(n*(n-1)*(n-3))/GCD(n,n-3);
  System.out.print(Math.max((n-1)*(n-2)*(n-3),temp));
  }
}


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

public class Main {
    Scanner cin = new Scanner(new BufferedInputStream(System.in));
    long n;
    long maxlcm;

    void run(){
    	n = cin.nextInt();
    	if(n == 1 || n ==2)
    		maxlcm = n;
    	else if(n >= 3){
            	if(n % 2 != 0){
    	           	maxlcm = n * (n-1) * (n - 2);
    	        }
            	else if(n%3 != 0)
            		maxlcm = n * (n - 1) * (n - 3);
            	else maxlcm = (n - 1) * (n - 2) * (n - 3);
    	}
    	System.out.println(maxlcm);
    }

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

	}
}


import java.util.Scanner;
public class LCM {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		if(n < 3) {
			System.out.println(n);
		}
		else if(n % 2 != 0) {
			System.out.println(n * (n-1) * (n-2));
		}
		else if(n % 3 == 0) {
			System.out.println((n-1) * (n-2) * (n-3));
		}
		else {
			System.out.println(n * (n-1) * (n-3));
		}
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
Scanner input = new Scanner(System.in);
long x = input.nextLong();

if(x==1||x==2){System.out.println(x);

}
else if(x%2==0&&x>2&&x%3!=0){
    System.out.println((x)*(x-1)*(x-3));

}else if(x%2==0&&x%3==0){
    System.out.println((x-1)*(x-2)*(x-3));
}

else {System.out.println(x*(x-1)*(x-2));}
    }
}


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

public class LCMChallenge {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        long n = Long.parseLong(f.readLine());
        if (n == 1 || n == 2)
            System.out.println(n);
        else if (n % 2 == 1)
            System.out.println(n*(n-1)*(n-2));
        else
        {
            long prod = n*(n-1);
            long x = n-2;
            while (x > 0 && gcd(n,x) > 1 || gcd(n-1,x) > 1)
                x--;
            prod *= x;
            if ((n-1)*(n-2)*(n-3) > prod)
                prod = (n-1)*(n-2)*(n-3);
            System.out.println(prod);
        }
    }

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


import java.util.Scanner;
public class test5{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
            long x=in.nextLong();
            if(x>=3){
                if(x%2!=0)
                    System.out.println(x*(x-1)*(x-2));
                else if(x%3==0)
                    System.out.println((x-3)*(x-1)*(x-2));
                else
                    System.out.println(x*(x-1)*(x-3));
            }
            else System.out.println(x);
    }
}


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

public class LCM {
	public static long gcd(long a,long b) {
		while(true) {
	    	a=a%b;
		  	if (a==0) return b;
		    b=b%a;
		    if (b==0) return a;
		}
    }
	public static void main (String[] args) throws java.lang.Exception {
		Scanner in=new Scanner(System.in);
		long n=in.nextInt();
		if (n>2) {
			if (gcd(n,n-2)>1) {
				if (gcd(n,n-3)>1) {
					System.out.println((n-1)*(n-2)*(n-3));
				}
				else System.out.println(n*(n-1)*(n-3));
			}
			else System.out.println(n*(n-1)*(n-2));
		}
		else System.out.println(n);
	}
}


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

public class Main {

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

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                            //(new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;
        //PrintWriter pw = new PrintWriter("output.out", "UTF-8");

        long n = parseLong(in.readLine());

        if(n <= 2) System.out.println(n);
        else if(n%2 == 1)System.out.println(n*(n-1)*(n-2));
        else {
            long ans = (n-1)*(n-2)*(n-3);

            if(gcd(n*(n-1),n-3)==1) ans = max(ans, n*(n-1)*(n-3));

            System.out.println(ans);
        }
    }

    static long gcd(long a,long b) {
        return b==0 ? a : gcd(b, a%b);
    }
}


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

public class Main {
    public static Scanner scan = new Scanner(System.in);
    public static boolean bg = true;

    public static void main(String[] args) throws Exception {
        long n1 = Integer.parseInt(scan.next());
        if (n1==1){
            System.out.println(1);
            System.exit(0);
        }
        if (n1==2){
            System.out.println(2);
            System.exit(0);
        }
        if (n1==3){
            System.out.println(6);
            System.exit(0);
        }
        if (n1%2==0){
            if (n1%3==0){
                n1-=1;
                n1 = n1*(n1-1)*(n1-2);
                System.out.println(n1);
            }
            else {
                n1 = n1*(n1-1)*(n1-3);
                System.out.println(n1);
            }
        }
        else {
            n1 = n1*(n1-1)*(n1-2);
            System.out.println(n1);
        }
    }
}


import java.util.Scanner;

public class Prob235A {
	public static void main(String[] Args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		if (x < 3) {
			if (x == 1)
				System.out.println(1);
			else
				System.out.println(2);
		} else {
			long answer = x;
			if (x % 2 == 1) {
				answer *= x - 1;
				answer *= x - 2;
			} else if (x % 3 != 0) {
				answer *= x - 1;
				answer *= x - 3;
			} else {
				answer = x - 1;
				answer *= x - 2;
				answer *= x - 3;
			}
			System.out.println(answer);
		}
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nipuna Samarasekara
 */
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();
	}
}

class TaskA {
    /////////////////////////////////////////////////////////////

    public void solve(int testNumber, FastScanner in, FastPrinter out) {
    int n=in.nextInt();
        if(n==1||n==2){
            out.println(n);
            return;
        }
        if(n==4){
            out.println(12);
            return;
        }
     long nn=n;
        if(n%2==1){
        long ans=nn*(nn-1)*(nn-2);
            out.println(ans);
        }
        else if(n%3==0){
            nn--;
            long ans=nn*(nn-1)*(nn-2);
            out.println(ans);

        }
        else {
            long ans=nn*(nn-1)*(nn-3);
            out.println(ans);

        }

    }
    }

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (c >= 0 && !isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    }

class FastPrinter extends PrintWriter {

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

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

}


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

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

long n=Long.parseLong(br.readLine());
if(n<=2)
System.out.println(n);
else
{

 if(n%6==0)
{
 System.out.println(((n-1)*(n-2)*(n-3)));
}
 else if(n%2==0)
{
  System.out.println((n*(n-1)*(n-3)));
}
else
{
  System.out.println((n*(n-1)*(n-2)));
}
}

}
}


import java.util.*;

public class LCM235A
{
    public static void main(String[] args)
    {
        // Set up scanner
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter n");
        long n = sc.nextLong();

        if (n==1)
        {
            System.out.println(1);
            return;
        }
        if (n==2)
        {
            System.out.println(2);
            return;
        }
        if (n==3)
        {
            System.out.println(6);
            return;
        }
        if (n==4)
        {
            System.out.println(12);
            return;
        }

        if (n%2 ==1)   // Odd number easy
        {
            System.out.println(n*(n-1)*(n-2));
            return;
        }

        // Even number is a bit harder
        if (n%3 == 0)
        {
            System.out.println((n-1)*(n-2)*(n-3));
        }
        else
        {
            System.out.println(n*(n-1)*(n-3));
        }
    }
}


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

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

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long n = in.readInt();
        if(n < 3){
            out.print(n);
        }
        else if(n % 2 != 0) {
            out.print(n * (n-1) * (n-2));
        }
        else if(n % 3 == 0) {
            out.print((n-1) * (n-2) * (n-3));
        }
        else {
            out.print(n * (n-1) * (n-3));
        }
    }
}

class InputReader {

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

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

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

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

	public 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.io.BufferedInputStream;
import java.util.Scanner;

/**
 * Created by jizhe on 2016/1/29.
 */
public class LCMChallenge {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));

        long N = in.nextLong();
        if( N == 1 || N == 2 )
        {
            System.out.printf("%d\n", N);
            return;
        }

        if( (N&1) == 1 )
        {
            long lcm = N*(N-1)*(N-2);
            System.out.printf("%d\n", lcm);
        }
        else
        {
            long lcm;
            if( N%3 == 0 )
            {
                lcm = (N-1)*(N-2)*(N-3);
            }
            else
            {
                lcm = N*(N-1)*(N-3);
            }

            System.out.printf("%d\n", lcm);
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       Long N = sc.nextLong();
       Long ans;
       sc.close();
       if(N <= 2)
           System.out.println(N);
       else{
           if(N % 6 == 0){
                ans = (N - 1) * (N - 2) * (N - 3);}
            else if(N % 2 == 0){
                ans = N * (N - 1) * (N - 3);
            }
            else{
                ans = N * (N - 1) * (N - 2);
            }
           System.out.println(ans);
       }
    }
}


import java.util.Scanner;
public class Solution {
    public static void main(String [] args){
        Scanner stdin = new Scanner(System.in);
        long n = stdin.nextLong();
        if(n<3)	System.out.println(n);
        else {
            if(n%2==0){
                long a=0,b=0;
                if(n%3!=0)	a = (n*(n-1)*(n-3));
                n--;
                b = (n*(n-1)*(n-2));
                System.out.println(Math.max(a, b));
            }
            else	System.out.println(n*(n-1)*(n-2));
        }
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        if (n == 1 || n == 2) {
            System.out.println(n);
        } else if (n % 2 == 0) {
            if (n % 3 == 0)
                System.out.println((n - 1) * (n - 2) * (n - 3));
            else
                System.out.println(n * (n - 1) * (n - 3));
        } else {
            System.out.println(n * (n - 1) * (n - 2));
        }
    }

}


import java.io.PrintStream;
import java.util.Scanner;

/**
 * @author Roman Elizarov
 */
public class Round_146_A {
	public static void main(String[] args) {
		new Round_146_A().go();
	}

	void go() {
		// read input
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		// solve
		long result = solve(n);

		// write result
		PrintStream out = System.out;
		out.println(result);
	}

	static long solve(int n) {
        if (n == 1)
            return 1;
        if (n == 2)
            return 2;
        if (n % 2 == 0) {
            if (n % 3 == 0)
                return (long)(n - 1) * (n - 2) * (n - 3);
            else
                return (long)n * (n - 1) * (n - 3);
        } else
		    return (long)n * (n - 1) * (n - 2);
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        //inputs
        long n = in.nextLong();
        if(n == 1)
            System.out.println(1);
        else if(n == 2)
            System.out.println(2);

        else if(n % 2 == 0){

            int cnt = nPrime(n);
            if(cnt == 1)
            System.out.println((n) * (n-1) * (n-3));
        else if(cnt > 1)
            System.out.println((n-1) * (n-2) * (n-3));
        }

        else
            System.out.println((n) * (n-1) * (n-2));
      }

    public static int nPrime(long n){
        int cnt=1;
        if(n % 3 == 0)
            cnt++;
        return cnt;
    }
    }


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

public class lcm {
	static int n;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("lcm.in"));
		n = Integer.parseInt(in.readLine());
		System.out.println(lcm(n));
		in.close();
	}

	static long lcm(int n) {
		if (n == 1) return 1;
		if (n == 2) return 2;

		if(n%6==0) {
			long ans = n-1;
			ans *= n-2;
			ans *= n-3;
			return ans;
		}

		if (n%2==0) {
			long ans = n;
			ans *= n-1;
			ans *= n-3;
			return ans;
		}

		long ans = n;
		ans *= n-1;
		ans *= n-2;
		return ans;
	}
}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
/** Oct 21, 2012 **/
import java.util.InputMismatchException;
import java.util.LinkedList;

/**
 * @author DOAN Minh Quy
 * @email mquy.doan@gmail.com
 */
public class C236 {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new C236().run();
    }
    void run() {
        InputScanner scanner = new InputScanner(System.in);
        PrintStream printer = new PrintStream(System.out);
        int n = scanner.nextInt();
        long answer;
        if ( n == 1 ){
            answer = 1;
        }else if ( n == 2 ){
            answer = 2;
        }else{
            if ( (n & 1) != 0 ){
                answer = (long)n * (long)(n-1) * (long)(n-2);
            }else{
                if ( n % 3 == 0 ){
                    answer = (long)(n-1) * (long)(n-2) * (long)(n-3);
                }else{
                    answer = (long)(n) * (long)(n-1) * (long)(n-3);
                }
            }
        }
        printer.println(answer);
    }
    class InputScanner{
        BufferedInputStream bis;
        byte[] buffer = new byte[1024];
        int currentChar;
        int charCount;
        public InputScanner(InputStream stream){
            bis = new BufferedInputStream(stream);
        }
        public byte read() {
            if (charCount == -1)
                throw new InputMismatchException();
            if (currentChar >= charCount) {
                currentChar = 0;
                try {
                    charCount = bis.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (charCount <= 0)
                    return -1;
            }
            return buffer[currentChar++];
        }
        public int nextInt(){
            int c = read();
            while (isSpaceChar(c)){
                c = read();
            }
            int sign = 1;
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int rep = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                rep *= 10;
                rep += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return rep * sign;
        }
        public long nextLong(){
            int c = read();
            while (isSpaceChar(c)){
                c = read();
            }
            int sign = 1;
            if (c == '-') {
                sign = -1;
                c = read();
            }
            long rep = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                rep *= 10;
                rep += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return rep * (long)sign;
        }
        public String next(){
            char c = (char)read();
            while (isSpaceChar(c)){
                c = (char)read();
            }
            StringBuilder build = new StringBuilder();
            do{
                build.append(c);
                c = (char)read();
            }while(!isSpaceChar(c));
            return build.toString();
        }
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        public void close(){
            try {
                bis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}


import java.util.*;
import java.io.*;
public class LCMChallenge
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();

		if(n < 3)
		{
			System.out.println(n);
		}
		else if(n % 2 == 1)
		{
			System.out.println((long)n * (n - 1) * (n - 2));
		}
		else
		{
			if(n % 3 != 0)
			{
				System.out.println((long)n * (n - 1) * (n - 3));
			}
			else
			{
				System.out.println((long)(n - 1) * (n - 2) * (n - 3));
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class A235 {
    public static void main(String args[]) throws Exception{
        BufferedReader ip = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(ip.readLine());
        int a,b,c;
        int x = 0,y = 0,z = 0;
        BigInteger l,t;

        if(n-2 > 1)
        {
            a = n;
            b = n-1;
            c = n-2;
        }
        else
        {
            a = n;
            if(n-1 > 1)
                b = n-1;
            else
                b = 1;
            c = 1;

            System.out.println(a*b);
            return;
        }

        if(n-3 > 1)
        {
            x = n-1;
            y = n-2;
            z = n-3;
        }

        if(n % 2 == 0)
            if(n % 3 == 0)
                l = BigInteger.valueOf(x).multiply(BigInteger.valueOf(y).multiply(BigInteger.valueOf(z)));
            else
            {
                l = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b).multiply(BigInteger.valueOf(c-1)));
                t = BigInteger.valueOf(x).multiply(BigInteger.valueOf(y).multiply(BigInteger.valueOf(z)));
                if(l.compareTo(t) < 0)
                    l = t;
            }
        else
            l = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b).multiply(BigInteger.valueOf(c)));

        System.out.println(l);
    }
}


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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int N = in.nextInt();

            if (N == 1) {
                out.println(1);
            } else if (N == 2) {
                out.println(2);
            } else if (N == 3) {
                out.println(6);
            } else {

                long best = Long.MIN_VALUE;
                best = Math.max(best, lcm(N, lcm(N - 1, N - 2)));
                best = Math.max(best, lcm(N, lcm(N - 2, N - 3)));
                best = Math.max(best, lcm(N, lcm(N - 1, N - 3)));
                best = Math.max(best, lcm(N - 1, lcm(N - 2, N - 3)));

                out.println(best);
            }
        }

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

        private long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }

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

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

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

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

    }
}


import java.util.Scanner;

public class A235 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long a = in.nextLong();
		if (a % 2 == 0) {
			long result = cal(a);
			result = Math.max(result, cal(a + 1));
			result = Math.max(result, cal2(a));
			System.out.println(Math.max(result, a));
		}

		else {
			long result = (a - 1) * (a - 2) * (a - 0);
			System.out.println(Math.max(result, a));
		}
	}

	static long cal(long a) {
		long result = (a - 1) * (a - 2);
		result /= gcd(a - 1, a - 2);
		long gcd = gcd(result, a - 3);
		result *= (a - 3);
		result /= gcd;
		return result;
	}

	static long cal2(long a) {
		long result = (a) * (a - 1);
		result /= gcd(a - 1, a);
		long gcd = gcd(result, a - 3);
		result *= (a - 3);
		result /= gcd;
		return result;
	}

	private static long gcd(long l, long i) {
		if (l == 0 || i == 0) {
			return 1;
		}
		if (l % i == 0) {
			return i;
		}
		return gcd(i, l % i);
	}
}


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

public class Main {
	boolean eof;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "-1";
			}
		}
		return st.nextToken();
	}

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

	void solve() {
		long n = nextInt(), ans = n;
		if (n % 6 == 0) {
			ans = Math.max((n - 1) * (n - 2) * (n - 3), ans);
		} else if (n % 2 == 0) {
			ans = Math.max(ans, n * (n - 1) * (n - 3));
		} else {
			ans = Math.max(n * (n - 1) * (n - 2), ans);
		}
		out.print(ans);
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));

			// br = new BufferedReader(new FileReader("input.txt"));
			// out = new PrintWriter(new FileWriter("output.txt"));

			solve();

			br.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

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


import java.util.Scanner;

public class CF{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		TaskA t = new TaskA();
		System.out.println(t.solve(n));
	}
}

class TaskA{
	public long solve(long n)
	{
		if(n < 3)
			return n;
		else if(n % 2 == 1)
			return n * (n-1) * (n-2);
		else if(n % 3 != 0)
			return n * (n-1) * (n-3);
		else
			return (n-1) * (n-2) * (n-3);
	}
}


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

public class Challenge {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();

		if (n == 1) {
			out.println("1");
		} else if (n == 2) {
			out.println("2");
		} else if (n == 3) {
			out.println("6");
		} else if (n%2 > 0) {
			out.println(1L * n * (n-1) * (n-2));
		} else if (n%3 == 0) {
			out.println(1L * (n-1) * (n-2) * (n-3));
		} else {
			out.println(1L * n * (n-1) * (n-3));
		}
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

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

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

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

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


import java.util.Scanner;

/**
 * 2013.07.27 No.1 235A LCM Challenge
 * 数论 n%2 == 0?     n%3 == 0?
 * @author Administrator *
 */

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if (n < 3)
            System.out.println(n);
        else if (n % 2 != 0)
            System.out.println((long)n * (n - 1) * (n - 2));
        else if(n % 3 != 0)
            System.out.println((long)n * (n - 1) * (n - 3));
        else
            System.out.println((long)(n - 1) * (n - 2) * (n - 3));
        in.close();

    }
}


import java.util.*;
public class LCMChallenge {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextInt();
		if(n == 1l)
			System.out.println(1);
		else if(n == 2l)
			System.out.println(2);
		else
		{
			long c1 = n*(n-1)*(n-2);
			long c2 = n*(n-1)*(n-3);
			long c3 = (n-1)*(n-2)*(n-3);
			if(n%2==0)
				c1/=2;
			else
				c3/=2;
			if(n%3==0)
				c2/=3;
			long ans = Math.max(c1, c2);
			ans = Math.max(ans, c3);
			System.out.println(ans);
		}
	}
}


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

public class LCMChallenge {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        if (n < 3) {
            System.out.println(n);
        } else if (n % 2 == 1) {
            System.out.println((long) n * (n - 1) * (n - 2));
        } else {
            if (n % 3 != 0) {
                System.out.println((long) n * (n - 1) * (n - 3));
            } else {
                System.out.println((long) (n - 1) * (n - 2) * (n - 3));
            }
        }
    }
}


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

public class Main {

    long n;
    long maxlcm;

    void run(){
    	n = cin.nextInt();
    	if(n == 1 || n ==2)
    		maxlcm = n;
    	else if(n >= 3){
            	if(n % 2 != 0){
    	           	maxlcm = n * (n-1) * (n - 2);
    	        }
            	else if(n%3 != 0)
            		maxlcm = n * (n-1) * (n - 3);
            	else maxlcm = (n - 1) * (n - 2) * (n - 3);
    	}
    	System.out.println(maxlcm);
    }

	public static void main(String[] args) {
		 new Main().run();
	}
	Scanner cin = new Scanner(new BufferedInputStream(System.in));
}


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

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

		int n = sc.nextInt();

		if(n < 3)
			out.println(n);
		else
		{
			if((n & 1) == 1)
				out.println(lcm(n, lcm(n - 1, n - 2)));
			else
				out.println(Math.max(lcm(n - 1, lcm(n - 2, n - 3)), lcm(n, lcm(n - 1, n - 3))));
		}
		out.flush();
		out.close();
	}

	static long gcd(long a, long b)
	{
		while(b != 0)
		{
			a = a%b;
			b ^= a;
			a ^= b;
			b ^= a;
		}
		return a;

	}

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

class InputReader {
	private BufferedReader reader;
	private StringTokenizer tokenizer;

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

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

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

}


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

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

class TaskA {
	public void solve(int testNumber, Scanner in, PrintWriter out) {
        long n = in.nextLong();

        if(n == 1) out.println("1");
        else if(n == 2) out.println("2");
        else if(n%2 == 1) out.println(n*(n-1)*(n-2));
        else if(n%6 == 0) out.println((n-1)*(n-2)*(n-3));
        else out.println(n*(n-1)*(n-3));
	}
}


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

public class AAA {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n=Integer.parseInt(st.nextToken());
		int m=Integer.parseInt(st.nextToken());
		String a="";
		String b="";
		for(int i=0;i<1129;i++) {
			a+="1";
			b+="8";
		}
		a+="9";
		b+="1";

		System.out.println(a);
		System.out.println(b);
	}

}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class B {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        // int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        StringBuilder ans1 = new StringBuilder();
        StringBuilder ans2 = new StringBuilder();
        for(int i=0; i<2229; i++) ans1.append('5');
        ans1.append('6');
        for(int i=0; i<2230; i++) ans2.append('4');
        out.println(ans1.toString());
        out.println(ans2.toString());
        out.close(); System.exit(0);
    }
}


import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String s1[]=br.readLine().split(" ");
            int n=Integer.parseInt(s1[0]);
            int S=Integer.parseInt(s1[1]);
            if(S%n==0)
             System.out.println(S/n);
            else
             System.out.println(S/n+1);
      }
}


import java.io.*;
public class coins
{
 public static void main(String args[])throws IOException
 {
  InputStreamReader read=new InputStreamReader(System.in);
  BufferedReader in=new BufferedReader(read);
  int i,k,n,v;
  String a;
  a=in.readLine();
  for(i=0;i<a.length();i++)
  {
   if(a.charAt(i)==' ')
   break;
  }
  n=Integer.parseInt(a.substring(0,i));
  v=Integer.parseInt(a.substring(i+1));
  k=v%n;
  v=v/n;
  if(k>0)
  v++;
  System.out.println(v);
 }
}


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

public class A {
    public static void main(String args[]) {
        FastScanner scn = new FastScanner();
        int n = scn.nextInt();
        int s = scn.nextInt();
        if (s <= n) {
            System.out.println(1);
        } else if (s > n) {
            if(s%n == 0){
                System.out.println(s/n);
            } else {
                System.out.println(s/n + 1);
            }
        }

    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


import java.util.*;

public class A912 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();
		long x = scan.nextInt();
		long y = scan.nextInt();
		long z = scan.nextInt();

		long requiredA = x * 2 + y;
		long requiredB = y + z * 3;

		long neededA = Math.max(0, requiredA - A);
		long neededB = Math.max(0, requiredB - B);
		System.out.print(neededA + neededB);
	}

}


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

public class A267 {

    static  public  long _solve(long a,long b){
        long result = -1;
        while(a!=0 && b!=0){
            if(a>b){
                result +=(a/b);
                a = a%b;
            }
            else{
                result +=(b/a);
                b = b%a;
            }
        }
        return result+1;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        long a,b;
        while(t-- > 0){
            a = in.nextLong();
            b = in.nextLong();
            System.out.println(_solve(a,b));
        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

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

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

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

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

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

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


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

public class Coder{

    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(System.in));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }
    }

    public static void main(String[] args) throws IOException{
        FastScanner s = new FastScanner();
        PrintWriter ww = new PrintWriter(new OutputStreamWriter(System.out));
        int test = s.nextInt(); int cnt=0;
        while(test-->0){
            int a = s.nextInt();
            int b = s.nextInt();
            cnt=0;
            while(a!=0 && b!=0){
                int max = Math.max(a, b);
                if(max == b){
                    int divi = b/a;
                    b -= divi*a;
                    cnt+=divi;
                }else{
                    int divi = a/b;
                    a -= divi*b;
                    cnt+=divi;
                }
        //      System.out.println(a+" "+b);
            }
            ww.println(cnt);
        }
        ww.close();
    }
}


import java.util.*;
public class Solution{

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int pairs = in.nextInt();
        while (pairs > 0){
            in.nextLine();
            int a = in.nextInt();
            int b = in.nextInt();
            int count = 0;
            while (a != 0 && b != 0){
                if (b >= a && a != 0){
                    count += b/a;
                    b = b%a;
                }
                if (a > b && b != 0){
                    count += a/b;
                    a = a%b;
                }
            }
            System.out.println(count);
            pairs--;
        }
    }

}


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

public class Mai {

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

		int t, n, m;

		t = cin.nextInt();

		while(t > 0) {
			t--;
			int sum = 0;
			n = cin.nextInt();
			m = cin.nextInt();
			while(n > 0 && m > 0) {
				if(n < m) {
					int k = n;
					n = m;
					m = k;
				}
				sum += n / m; n %= m;
			}

			System.out.println(sum);
		}
	}

}


import java.util.Scanner;

/**
 * Created by carolineshi on 3/30/17.
 */
public class Subtractions {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        while(t != 0) {
            int f = scan.nextInt();
            int s = scan.nextInt();
            System.out.println(ops(f, s));
            t--;
        }
    }

    public static int ops(int f, int s) {
        int ops = 0;

        while((f > 0) && (s > 0)) {
            if(f > s) {
                ops += f/s;
                f %= s;
            } else {
                //f <= s
                ops += s/f;
                s %= f;
            }
        }

        return ops;
    }

}


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

public class CodeForces {

	public static void main(String[] args) throws IOException,NumberFormatException{
		try {
			FastScanner sc=new FastScanner();
			int t=sc.nextInt();
			while(t-->0) {
				int a=sc.nextInt(),b=sc.nextInt();
				int count=0;
				while(a!=0&&b!=0) {
					if(a>b) {
						int temp=a;
						a=b;
						b=temp;
					}
				    count+=(b/a);
				    b=b%a;
				}
				System.out.println(count);
			}

		}
		catch(Exception e) {
			return ;
		}

	}

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

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

	}
}


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

public class CF267A {

	public static void main(String[] args) {
		int n=0, a, b;
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		try {
			n = Integer.parseInt(stdin.readLine());
		} catch (IOException e) {
		}
		while(n-->0){
			String[] row = null;
			try {
				row = stdin.readLine().split(" ");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			a = Integer.parseInt(row[0]);
			b = Integer.parseInt(row[1]);
			if(a<b) System.out.println(calc(a,b));
			else System.out.println(calc(b,a));
		}
	}

	static int calc(int a, int b){
		if(a==0) return 0;
		if(a==b) return 1;
		if(a==1) return b;
		else return b/a+calc(b%a, a);
	}

}


//package A;

import java.util.Scanner;

public class Solution {
    Scanner in = new Scanner(System.in);
    void run() throws Exception {
        int tests = in.nextInt();
        while (tests > 0) {
            --tests;
            int a = in.nextInt();
            int b = in.nextInt();
            int res = 0;
            while (a > 0 && b > 0) {
                if (a >= b) {
                    res += a / b;
                    a %= b;
                }
                else {
                    res += b / a;
                    b %= a;
                }
            }
            System.out.println(res);
        }
    }
    public static void main(String args[]) throws Exception {
        new Solution().run();
    }
}


import java.util.Scanner;

public class Question267A {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while (t--!=0){
            int x=sc.nextInt();
            int y=sc.nextInt();
            int max=Math.max(x,y);
            int min=Math.min(x,y);
            int ans=0;
            while (min>0 && max>0){
                int temp=max;
                ans+=temp/min;
                max=min;
                min=temp%min;
           }
            System.out.println(ans);
        }
    }
}


import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        while(T!=0){
            T--;
            int a = in.nextInt();
            int b = in.nextInt();
            int ans=0;
            while(a>0&&b>0){
                if(a>b){
                    int c = a;
                    a = b;
                    b = c;
                }
                ans += (b-(b%a))/a;
                b = b%a;
            }
            System.out.println(ans);
        }
    }

}


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

public class Subtraction {
    static long c=0;
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(reader.readLine());
        while (n-->0){
            String l=reader.readLine();
            String[] a=l.split(" ");
            long A=Long.parseLong(a[0]);
            long B=Long.parseLong(a[1]);
            c=0;
            gcd(A,B);
            System.out.println(c);
        }
    }

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


import java.util.*;

public class Subtractions {

	public static void main(String[] args) {
		Scanner kb = new Scanner(System.in);
		int count = kb.nextInt();
		while(count > 0) {
			int smaller = kb.nextInt();
			int larger = kb.nextInt();
			int ops = 0;

			while(smaller > 0 && larger > 0) {
				if(smaller > larger) {
					int temp = smaller;
					smaller = larger;
					larger = temp;
				}

				ops += larger/smaller;
				larger = larger % smaller;
			}
			System.out.println(ops);
			count--;
		}

	}

}


import java.util.Scanner;

public class Sub
{
	public static void main(String[] args)
	{
		Scanner scan=new Scanner(System.in);
		int noOfPairs=scan.nextInt();
		while(noOfPairs-->0)
		{
			int x=scan.nextInt();
			int y=scan.nextInt();
			int res=0;
			while(x!=0&&y!=0)
			{
			  if(x>y)
			   {
				res+=x/y;
				x=x%y;
			   }
			  else
			   {
				  res+=y/x;
				  y=y%x;
			   }
			}
			System.out.println(res);
		}
		scan.close();
	}
}


import java.util.Scanner;

public class Subtractions {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		while(t--!=0){
			int a=s.nextInt();
			int b=s.nextInt();
			int min=Math.min(a, b);
			int max=Math.max(a, b);
			int ops=0;
			while(true){
				int quo=max/min;
				ops+=quo;
				int rem=max%min;
				max=Math.max(rem, min);
				min=Math.min(min, rem);
				if(rem==0) break;
			}
			System.out.println(ops);
		}
	}

}


//david alexander
import java.util.*;

public class Subtract {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a,b;
		String answer = "";
		while(n!=0){
			a = sc.nextInt();
			b = sc.nextInt();
			answer += solve(a,b) + "\n";
			n--;
		}
		System.out.println(answer);
	}

	public static int solve(int a, int b){
		int count = 0;
		int div;
		int mod;
		while(true){
			if(a >= b){
				div = a/b;
				mod = a%b;
				count += div;
				if(mod==0){
					return count;
				}
				else{
					a = mod;
				}
			}
			else{
				div = b/a;
				mod = b%a;
				count += div;
				if(mod==0){
					return count;
				}
				else{
					b = mod;
				}
			}
		}
	}
}


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

public class Main {

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

		int t, n, m;

		t = cin.nextInt();

		while(t > 0) {
			t--;
			int sum = 0;
			n = cin.nextInt();
			m = cin.nextInt();
			while(n > 0 && m > 0) {
				if(n < m) {
					int k = n;
					n = m;
					m = k;
				}
				sum += n / m; n %= m;
			}

			System.out.println(sum);
		}
	}

}


/*
(7 10)  1 2 3
(3, 7)
(1, 3)

(3, 7)
(3, 4)
(3, 1)
(2, 1)
(1, 1)
1

*/
import java.util.*;
public class CodeForcesW8P2 {

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

        int tests = Integer.valueOf(sc.nextLine());

        while(tests > 0){
            int count = 0;
            String [] input = sc.nextLine().split(" ");
            int x = Integer.valueOf(input[0]);
            int y = Integer.valueOf(input[1]);

            if (x == y){
                count += 1;
            }
            else {
                if (x > y){
                    int temp = x;
                    x = y;
                    y = temp;
                }
                /*
                    (4, 17) 4 + 4
                    (1, 4)

                    (4, 16) 4
                    (4, 12)
                    (4, 8)
                    (4, 4)

                */
                while (x != 1 && x != 0 && y != 1){
                    count += (y / x);
                    int temp = x;
                    x = (y % x);
                    y = temp;
                }
                if (x != 0)
                    count += y;

            }

            System.out.println(count);
            tests --;
        }

    }
}


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

public class Solution {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        s.nextLine();
        while(s.hasNext()) {
            int first = s.nextInt();
            int second = s.nextInt();
            System.out.println(calculate(first,second));
        }
    }

    public static int calculate(int first, int second) {
        int operations = 0;
        while(first != 0 && second != 0) {
            int temp;
            if(first < second) {
                temp = second/first;
                operations += temp;
                second -= (first*temp);
            }
            else {
                temp = first/second;
                operations += temp;
                first -= (second*temp);
            }
        }
        return operations;
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int t = in.readInt();
            while (t-- > 0) {
                int[] a = new int[]{in.readInt(), in.readInt()};
                Arrays.sort(a);
                int ans = 0;
                while (a[0] > 0) {
                    int x = a[1] / a[0];
                    ans += x;
                    a[1] -= a[0] * x;
                    Arrays.sort(a);
                }
                out.println(ans);

            }
        }

    }

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

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

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

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

        public 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 sub {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		while(num-->0) {
			int a = in.nextInt();
			int b = in.nextInt();

			int res = 0;

			while(a!=0 && b!=0) {
				if(a>=b) {
					res += a/b;
					a %= b;
				} else {
					res += b/a;
					b %= a;
				}
			}
			System.out.println(res);
		}
	}
}


import java.util.Scanner;

public class Subtractions {

	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int test=sc.nextInt();
		while(test-->0){
			long a=sc.nextLong();
			long b=sc.nextLong();
			long count=0;
			long cnt=0;
			while(a>0&&b>0){
				count=0;
				//System.out.println(a+" "+b);
			if(a>b){
			count+=(a-b)/b;
			if(count!=0){
			cnt+=count;
			a-=b*count;}
			else {
				cnt++;
				a-=b;
			}
			}
			else{
				count+=(b-a)/a;
				if(count!=0){
				cnt+=count;
			b-=a*count;}
				else {
					cnt++;
					b-=a;
				}
			}
			}
		System.out.println(cnt);
		}

	}

}


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

public class StrangeAddition {

	public static void main(String[] args) throws IOException {
		PrintWriter out = new PrintWriter(System.out);
		sc = new StringTokenizer(br.readLine());
		int tc = nxtInt();
		while (tc-- > 0) {
			int a = nxtInt();
			int b = nxtInt();
			int ans = 0;
			while (a != b) {
				if (a == 0 || b == 0)
					break;
				if (a > b) {
					int div = a / b;
					a -= b * div;
					ans += div;
				} else {
					int div = b / a;
					b -= a * div;
					ans += div;
				}
			}
			out.println(ans + (a == b ? 1 : 0));
		}
		br.close();
		out.close();
	}

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

	static StringTokenizer sc;

	static String nxtTok() throws IOException {
		while (!sc.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null)
				return null;
			sc = new StringTokenizer(s.trim());
		}
		return sc.nextToken();
	}

	static int nxtInt() throws IOException {
		return Integer.parseInt(nxtTok());
	}

	static long nxtLng() throws IOException {
		return Long.parseLong(nxtTok());
	}
}


import java.util.Scanner;

public class Subtractions {

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        while (t-- > 0) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            int res = 0;
            while (a != 0 && b != 0) {
                if (a > b) {
                    res += (a / b);
                    a %= b;
                } else {
                    res += (b / a);
                    b %= a;
                }
            }
            System.out.println(res);

        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author John Martin
 */
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);
        ASubtractions solver = new ASubtractions();
        solver.solve(1, in, out);
        out.close();
    }

    static class ASubtractions {
        public void solve(int testNumber, InputReader c, OutputWriter w) {
            int tc = c.readInt();
            while (tc-- > 0) {
                int a = c.readInt(), b = c.readInt();
                int res = 0;
                while (a != 0 && b != 0) {
                    res += b / a;
                    b = b % a;
                    int t = b;
                    b = a;
                    a = t;
                }
                w.printLine(res);
            }
        }

    }

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

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

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

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

        public 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);

        }

    }

    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 printLine(int i) {
            writer.println(i);
        }

    }
}


//package Demo;

//import java.io.Console;
import java.util.Scanner;

//import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while(T-->0){
            int m , n , count=0;
            m = scanner.nextInt();
            n = scanner.nextInt();
            while(m!=0&&n!=0){
                int tmp;
                if(m<n) {
                    tmp = n;
                    n = m;
                    m = tmp;
                }
                count+=m/n;
                m = m%n;
            }
            if(T!=0)System.out.println(count);
            else System.out.print(count);
        }
    }

}


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

	/************************ SOLUTION STARTS HERE ***********************/

	static long modifiedEuclidGCD(int a , int b) {
		return b == 0 ? 0 : (a / b) + modifiedEuclidGCD(b, a % b);
	}

	private static void solve(FastScanner s1, PrintWriter out){

		int T = s1.nextInt();
		while(T-->0)
			out.println(modifiedEuclidGCD(s1.nextInt(), s1.nextInt()));

	}

	/************************ SOLUTION ENDS HERE ************************/

	/************************ 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[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}
		long[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}
		int[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}
		long[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}
		void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
	}

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


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

public class Main {
	public static int gcd(int a , int b) {
		if (b == 0) return 0;
		else {
			return a / b + gcd (b , a % b);
		}
	}

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

		while (testCase-- > 0) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if (n < m) {
				int temp = n;
				n = m;
				m = temp;
			}

			int ans = gcd (n , m);
			System.out.println(ans);
		}
	}
}


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

public class A {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	long f(int x, int y) {
		if (x == 0 || y == 0)
			return 0;
		if (x >= y) {
			return x / y + f(y, x % y);
		} else {
			return y / x + f(x, y % x);
		}
	}

	A() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int t = nextInt();
		while (t-- > 0) {
			int a = nextInt();
			int b = nextInt();
			out.println(f(a, b));
		}
		out.close();
	}

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

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

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

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

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


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

public class Task267A {

	public static void main(String... args) throws NumberFormatException,
			IOException {
		Solution.main(System.in, System.out);
	}

	static class Scanner {

		private final BufferedReader br;
		private String[] cache;
		private int cacheIndex;

		Scanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			cache = new String[0];
			cacheIndex = 0;
		}

		int nextInt() throws IOException {
			if (cacheIndex >= cache.length) {
				cache = br.readLine().split(" ");
				cacheIndex = 0;
			}
			return Integer.parseInt(cache[cacheIndex++]);
		}

		String next() throws IOException {
			if (cacheIndex >= cache.length) {
				cache = br.readLine().split(" ");
				cacheIndex = 0;
			}
			return cache[cacheIndex++];
		}

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

	}

	static class Solution {

		public static void main(InputStream is, OutputStream os)
				throws NumberFormatException, IOException {
			PrintWriter pw = new PrintWriter(os);
			Scanner sc = new Scanner(is);

			int n = sc.nextInt();

			while (n-- > 0) {
				int ai = sc.nextInt();
				int bi = sc.nextInt();
				int retVal = 0;

				while (ai > 0 && bi > 0) {
					if (ai > bi) {
						retVal += ai / bi;
						ai = ai % bi;
					} else {
						retVal += bi / ai;
						bi = bi % ai;
					}
				}
				pw.println(retVal);
			}

			pw.flush();
			sc.close();
		}
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a, b, min, max, result = 0, temp;
		while(n-->0){
			a = sc.nextInt();
			b = sc.nextInt();
			max = Math.max(a, b);
			min = Math.min(a, b);
			result = 0;
			while(true){
				result += max/min;
				if(max%min == 0){
					System.out.println(result);
					break;
				}
				/* take the min and the remainder as the previous min. */
				temp = max;
				max = min;
				min = temp%min;
			}
		}
		sc.close();
	}

}