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

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=0,maxi=0,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			if(a[j]>mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=Math.min(mini+1,maxi+1);
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


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

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=0,maxi=0,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<=min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			/*else if(a[j]>=mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}*/
			mx=Math.max(a[j],mx);
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=mini+1;
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


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

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=-1,maxi=-1,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<=min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			if(a[j]>mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=Math.min(mini+1,maxi+1);
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


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

public final class Q2
{
	static int t, n, arr[];
	static InputReader in;
	static OutputWriter out;

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

		solve();

		out.flush();

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

	static void solve()
	{
		n = in.nextInt();

		arr = in.nextIntArray(n);

/*		int[] min, max;

		min = new int[n];
		max = new int[n];

		min[0] = arr[0];
		max[0] = arr[0];

		for (int i = 1; i < n; i++)
		{
			min[i] = Math.min(arr[i], min[i - 1]);
			max[i] = Math.max(arr[i], max[i - 1]);
		}*/

		int max, currLeft, currRight;

		max = 1;

		for (int i = 0; i <= n - max; i++)
		{
			int subMin, subMax;

			subMin = 1000000;
			subMax = 0;

			currLeft = i;

			subMin = subMax = arr[i];

			for (int j = currLeft + 1; j < n; j++)
			{
				if (arr[j] < subMin)
					subMin = arr[j];

				if (arr[j] > subMax)
					subMax = arr[j];

				if (subMax - subMin <= 1)
				{
					if (j - i + 1 > max)
					{
						max = j - i + 1;
//						System.out.println("max : " + max + ", j : " + j + ", i : " + i + ", min : " + subMin + ", max : " + subMax);
					}
				}
else
break;
			}
		}

		out.println(max);
	}

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

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

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

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

			return buf[curChar++];
		}

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

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

			int sgn = 1;

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

			int res = 0;

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

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

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

			return res * sgn;
		}

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

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

			return array;
		}

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

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

			int sign = 1;

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

				c = read();
			}

			long result = 0;

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

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

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

			return result * sign;
		}

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

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

			return array;
		}

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

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

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

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

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

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

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

			if (isNegative)
				return -result;

			return result;
		}

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

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

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

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

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

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

			if (neg)
				return -ret;

			return ret;
		}

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

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

			StringBuilder res = new StringBuilder();

			do
			{
				res.appendCodePoint(c);

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

			return res.toString();
		}

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

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

			StringBuilder result = new StringBuilder();

			do
			{
				result.appendCodePoint(c);

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

			return result.toString();
		}

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

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

	}

	static class OutputWriter
	{
		private PrintWriter writer;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	}

}

/*

9
1 2 2 2 3 3 3 3 3

9
1 2 2 2 1 2 3 3 1

*/


//package com.competitions.year2015.octobertodecember.round333div2;

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

public final class Q2
{
	static int t, n, arr[];
	static InputReader in;
	static OutputWriter out;

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

		solve();

		out.flush();

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

	static void solve()
	{
		n = in.nextInt();

		arr = in.nextIntArray(n);

/*		int[] min, max;

		min = new int[n];
		max = new int[n];

		min[0] = arr[0];
		max[0] = arr[0];

		for (int i = 1; i < n; i++)
		{
			min[i] = Math.min(arr[i], min[i - 1]);
			max[i] = Math.max(arr[i], max[i - 1]);
		}*/

		int max, currLeft, currRight;

		max = 1;

		for (int i = 1; i <= n - max; i++)
		{
			int subMin, subMax;

			subMin = 1000000;
			subMax = 0;

			currLeft = i;

			subMin = subMax = arr[i];

			for (int j = currLeft + 1; j < n; j++)
			{
				if (arr[j] < subMin)
					subMin = arr[j];

				if (arr[j] > subMax)
					subMax = arr[j];

				if (subMax - subMin <= 1)
				{
					if (j - i + 1 > max)
					{
						max = j - i + 1;
						//System.out.println("max : " + max + ", j : " + j + ", i : " + i + ", min : " + subMin + ", max : " + subMax);
					}
				}
			}
		}

		out.println(max);
	}

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

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

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

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

			return buf[curChar++];
		}

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

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

			int sgn = 1;

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

			int res = 0;

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

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

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

			return res * sgn;
		}

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

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

			return array;
		}

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

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

			int sign = 1;

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

				c = read();
			}

			long result = 0;

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

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

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

			return result * sign;
		}

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

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

			return array;
		}

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

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

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

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

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

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

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

			if (isNegative)
				return -result;

			return result;
		}

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

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

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

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

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

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

			if (neg)
				return -ret;

			return ret;
		}

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

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

			StringBuilder res = new StringBuilder();

			do
			{
				res.appendCodePoint(c);

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

			return res.toString();
		}

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

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

			StringBuilder result = new StringBuilder();

			do
			{
				result.appendCodePoint(c);

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

			return result.toString();
		}

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

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

	}

	static class OutputWriter
	{
		private PrintWriter writer;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	}

}


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

public final class Q2
{
	static int t, n, arr[];
	static InputReader in;
	static OutputWriter out;

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

		solve();

		out.flush();

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

	static void solve()
	{
		n = in.nextInt();

		arr = in.nextIntArray(n);

/*		int[] min, max;

		min = new int[n];
		max = new int[n];

		min[0] = arr[0];
		max[0] = arr[0];

		for (int i = 1; i < n; i++)
		{
			min[i] = Math.min(arr[i], min[i - 1]);
			max[i] = Math.max(arr[i], max[i - 1]);
		}*/

		int max, currLeft, currRight;

		max = 1;

		for (int i = 0; i <= n - max; i++)
		{
			int subMin, subMax;

			subMin = 1000000;
			subMax = 0;

			currLeft = i;

			subMin = subMax = arr[i];

			for (int j = currLeft + 1; j < n; j++)
			{
				if (arr[j] < subMin)
					subMin = arr[j];

				if (arr[j] > subMax)
					subMax = arr[j];

				if (subMax - subMin <= 1)
				{
					if (j - i + 1 > max)
					{
						max = j - i + 1;
//						System.out.println("max : " + max + ", j : " + j + ", i : " + i + ", min : " + subMin + ", max : " + subMax);
					}
				}
else
break;
			}
		}

		out.println(max);
	}

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

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

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

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

			return buf[curChar++];
		}

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

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

			int sgn = 1;

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

			int res = 0;

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

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

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

			return res * sgn;
		}

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

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

			return array;
		}

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

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

			int sign = 1;

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

				c = read();
			}

			long result = 0;

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

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

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

			return result * sign;
		}

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

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

			return array;
		}

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

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

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

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

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

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

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

			if (isNegative)
				return -result;

			return result;
		}

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

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

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

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

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

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

			if (neg)
				return -ret;

			return ret;
		}

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

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

			StringBuilder res = new StringBuilder();

			do
			{
				res.appendCodePoint(c);

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

			return res.toString();
		}

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

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

			StringBuilder result = new StringBuilder();

			do
			{
				result.appendCodePoint(c);

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

			return result.toString();
		}

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

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

	}

	static class OutputWriter
	{
		private PrintWriter writer;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	}

}

/*

9
1 2 2 2 3 3 3 3 3

9
1 2 2 2 1 2 3 3 1

*/


//package com.competitions.year2015.octobertodecember.round333div2;

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

public final class Q2
{
	static int t, n, arr[];
	static InputReader in;
	static OutputWriter out;

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

		solve();

		out.flush();

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

	static void solve()
	{
		n = in.nextInt();

		arr = in.nextIntArray(n);

/*		int[] min, max;

		min = new int[n];
		max = new int[n];

		min[0] = arr[0];
		max[0] = arr[0];

		for (int i = 1; i < n; i++)
		{
			min[i] = Math.min(arr[i], min[i - 1]);
			max[i] = Math.max(arr[i], max[i - 1]);
		}*/

		int max, currLeft, currRight;

		max = 1;
		currRight = 1;

		for (int i = 0; i <= n - max; i++)
		{
			int subMin, subMax;

			subMin = 1000000;
			subMax = 0;

			currLeft = i;

			subMin = subMax = arr[i];

			for (int j = currRight + 1; j < n; j++)
			{
				if (arr[j] < subMin)
					subMin = arr[j];

				if (arr[j] > subMax)
					subMax = arr[j];

				if (subMax - subMin <= 1)
				{
					if (j - i + 1 > max)
					{
						max = j - i + 1;
//						System.out.println("max : " + max + ", j : " + j + ", i : " + i + ", min : " + subMin + ", max : " + subMax);
						currRight = j;
					}
				}
			}
		}

		out.println(max);
	}

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

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

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

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

			return buf[curChar++];
		}

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

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

			int sgn = 1;

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

			int res = 0;

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

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

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

			return res * sgn;
		}

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

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

			return array;
		}

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

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

			int sign = 1;

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

				c = read();
			}

			long result = 0;

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

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

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

			return result * sign;
		}

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

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

			return array;
		}

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

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

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

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

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

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

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

			if (isNegative)
				return -result;

			return result;
		}

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

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

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

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

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

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

			if (neg)
				return -ret;

			return ret;
		}

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

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

			StringBuilder res = new StringBuilder();

			do
			{
				res.appendCodePoint(c);

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

			return res.toString();
		}

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

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

			StringBuilder result = new StringBuilder();

			do
			{
				result.appendCodePoint(c);

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

			return result.toString();
		}

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

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

	}

	static class OutputWriter
	{
		private PrintWriter writer;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	}

}

/*

9
1 2 2 2 3 3 3 3 3

9
1 2 2 2 1 2 3 3 1

*/


//package com.competitions.year2015.octobertodecember.round333div2;

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

public final class Q2
{
	static int t, n, arr[];
	static InputReader in;
	static OutputWriter out;

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

		solve();

		out.flush();

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

	static void solve()
	{
		n = in.nextInt();

		arr = in.nextIntArray(n);

/*		int[] min, max;

		min = new int[n];
		max = new int[n];

		min[0] = arr[0];
		max[0] = arr[0];

		for (int i = 1; i < n; i++)
		{
			min[i] = Math.min(arr[i], min[i - 1]);
			max[i] = Math.max(arr[i], max[i - 1]);
		}*/

		int max, currLeft, currRight;

		max = 1;

		for (int i = 0; i <= n - max; i++)
		{
			int subMin, subMax;

			subMin = 1000000;
			subMax = 0;

			currLeft = i;

			subMin = subMax = arr[i];

			for (int j = currLeft + 1; j < n; j++)
			{
				if (arr[j] < subMin)
					subMin = arr[j];

				if (arr[j] > subMax)
					subMax = arr[j];

				if (subMax - subMin <= 1)
				{
					if (j - i + 1 > max)
					{
						max = j - i + 1;
//						System.out.println("max : " + max + ", j : " + j + ", i : " + i + ", min : " + subMin + ", max : " + subMax);
					}
				}
			}
		}

		out.println(max);
	}

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

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

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

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

			return buf[curChar++];
		}

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

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

			int sgn = 1;

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

			int res = 0;

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

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

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

			return res * sgn;
		}

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

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

			return array;
		}

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

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

			int sign = 1;

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

				c = read();
			}

			long result = 0;

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

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

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

			return result * sign;
		}

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

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

			return array;
		}

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

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

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

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

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

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

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

			if (isNegative)
				return -result;

			return result;
		}

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

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

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

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

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

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

			if (neg)
				return -ret;

			return ret;
		}

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

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

			StringBuilder res = new StringBuilder();

			do
			{
				res.appendCodePoint(c);

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

			return res.toString();
		}

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

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

			StringBuilder result = new StringBuilder();

			do
			{
				result.appendCodePoint(c);

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

			return result.toString();
		}

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

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

	}

	static class OutputWriter
	{
		private PrintWriter writer;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	}

}

/*

9
1 2 2 2 3 3 3 3 3

9
1 2 2 2 1 2 3 3 1

*/


//package com.competitions.year2015.octobertodecember.round333div2;

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

public final class Q2
{
	static int t, n, arr[];
	static InputReader in;
	static OutputWriter out;

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

		solve2();

		out.flush();

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

	static void solve()
	{
		n = in.nextInt();

		arr = in.nextIntArray(n);

/*		int[] min, max;

		min = new int[n];
		max = new int[n];

		min[0] = arr[0];
		max[0] = arr[0];

		for (int i = 1; i < n; i++)
		{
			min[i] = Math.min(arr[i], min[i - 1]);
			max[i] = Math.max(arr[i], max[i - 1]);
		}*/

		int max, currLeft, currRight;

		max = 1;
		currRight = 0;

		for (int i = 0; i <= n - max; i++)
		{
			int subMin, subMax;

			subMin = 1000000;
			subMax = 0;

			currLeft = i;

			subMin = subMax = arr[i];

			for (int j = currRight + 1; j < n; j++)
			{
				if (arr[j] < subMin)
					subMin = arr[j];

				if (arr[j] > subMax)
					subMax = arr[j];

				if (subMax - subMin <= 1)
				{
					if (j - i + 1 > max)
					{
						max = j - i + 1;
//						System.out.println("max : " + max + ", j : " + j + ", i : " + i + ", min : " + subMin + ", max : " + subMax);
						currRight = j;
					}
				}
				else
					break;
			}
		}

		out.println(max);
	}

	static void solve2()
	{
		n = in.nextInt();
		arr = in.nextIntArray(n);

		int[] copy = Arrays.copyOf(arr, n);

		for (int i = 0; i < n; i++)
		{
			if (copy[i] % 2 == 1)
				copy[i]++;
		}

/*		System.out.println("after first : ");

		for (int i = 0; i < n; i++)
			System.out.print(copy[i] + " ");

		System.out.println();*/

		int maxLen, currLen;

		currLen = maxLen = 0;

		for (int i = 0; i < n;)
		{
			currLen = 0;
			int curr = copy[i];

			while (i < n && copy[i] == curr)
			{
				i++;
				currLen++;
			}

			if (currLen > maxLen)
			{
//				System.out.println("i : " + i + ", previous maxLen : " + maxLen + ", curr : " + currLen);
				maxLen = currLen;
			}
		}

		copy = Arrays.copyOf(arr, n);

		for (int i = 0; i < n; i++)
			if (copy[i] % 2 == 0)
				copy[i]++;

/*		System.out.println("after second :");

		for (int i = 0; i < n; i++)
			System.out.print(copy[i] + " ");

		System.out.println();*/

		for (int i = 0; i < n;)
		{
			currLen = 0;
			int curr = copy[i];

//			System.out.println("curr : " + curr + ", i : " + i);
			while (i < n && copy[i] == curr)
			{
				i++;
				currLen++;
			}

			if (currLen > maxLen)
			{
//				System.out.println("i : " + i + ", previous maxLen : " + maxLen + ", curr : " + currLen);
				maxLen = currLen;
			}
		}

		out.println(maxLen);
	}

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

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

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

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

			return buf[curChar++];
		}

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

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

			int sgn = 1;

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

			int res = 0;

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

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

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

			return res * sgn;
		}

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

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

			return array;
		}

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

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

			int sign = 1;

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

				c = read();
			}

			long result = 0;

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

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

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

			return result * sign;
		}

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

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

			return array;
		}

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

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

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

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

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

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

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

			if (isNegative)
				return -result;

			return result;
		}

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

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

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

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

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

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

			if (neg)
				return -ret;

			return ret;
		}

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

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

			StringBuilder res = new StringBuilder();

			do
			{
				res.appendCodePoint(c);

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

			return res.toString();
		}

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

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

			StringBuilder result = new StringBuilder();

			do
			{
				result.appendCodePoint(c);

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

			return result.toString();
		}

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

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

	}

	static class OutputWriter
	{
		private PrintWriter writer;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	}

}

/*

9
1 2 2 2 3 3 3 3 3

9
1 2 2 2 1 2 3 3 1

*/


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out,true);
		int n = sc.nextInt();
		long[] arr = new long[n];
		for(int i =0;i<n;i++){
			arr[i] = sc.nextLong();
		}
		int mLen = 1,lLen = 1;
		long ma =0,mi = 0;
		for(int i =0;i<n;i++){
			lLen = 1;
			ma = mi = arr[i];
			for(int j = i+1;j<n;j++){
				if(arr[j]>ma)ma = arr[j];
				if(arr[j]<mi)mi = arr[j];
				if(Math.abs(ma-mi)<=1)lLen++;
				else break;
			}
			if(lLen > mLen){
				mLen = lLen;
			}
		}
		out.println(mLen);
	}
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out,true);
		int n = sc.nextInt();
		long[] arr = new long[n];
		for(int i =0;i<n;i++){
			arr[i] = sc.nextLong();
		}
		long min = arr[0],max = arr[0];int inmin = 0,inmax =0,size=1,Msize=1;
		for(int i = 1;i<n;i++){
			if(arr[i]>max)max = arr[i];
			if(arr[i]<=min)min = arr[i];
			if(Math.abs(min-arr[i])<=1 && Math.abs(max-arr[i])<=1){
				size++;
				if(arr[i] == min)inmin = i;
				if(arr[i] == max)inmax = i;
				Msize = Math.max(Msize,size);
			}
			else if(arr[i] == max){
				size = 1;
				i = inmin + 1;
				if(i == arr.length)break;
				inmin = i;
				inmax = i;
				max = arr[i];min = arr[i];
			}
			else{
				size = 1;
				i = inmax + 1;
				if(i == arr.length)break;
				inmin = i;
				inmax = i;
				max = arr[i];min = arr[i];
			}

		}
		out.println(Msize);
	}
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out,true);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i =0;i<n;i++){
			arr[i] = sc.nextInt();
		}
		int[] diff = new int[n];
	    for(int i = 1;i<n;i++){
	    	diff[i] = arr[i]-arr[i-1];
	    	//out.println(diff[i]);
	    }
	    int l = 0,mLen = 1,lastseen = 0;
	    for(int i =1;i<n;i++){
	    	if(Math.abs(diff[i]) <= 1){
	    		if(diff[i] == lastseen && diff[i]!= 0){
	    			l = i-1;
	    			lastseen = diff[i];
	    		//	out.println("CASE 1");
	    		//	out.println(l);
	    		}
	    		else if(diff[i] != lastseen || (diff[i] == 0)){
	    			if(i-l+1 > mLen){
	    				mLen = i-l+1;
	    			}
	    			if(diff[i]!=0){
	    				lastseen = diff[i];
	    			}
	    		//	out.println("CASE 2");
	    		//	out.println(diff[i]);
	    		}
	    	}
	    	else{
	    		l = i-1;
	    	}
	    //	out.println(l);
	    }
	    out.println(mLen);
	}
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out,true);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i =0;i<n;i++){
			arr[i] = sc.nextInt();
		}
		int[] diff = new int[n];
	    for(int i = 0;i<n-1;i++){
	    	diff[i] = arr[i+1]-arr[i];
	    	//out.println(diff[i]);
	    }
	    int l = 0,mLen = 1,lastseen = 0;
	    for(int i =0;i<n-1;i++){
	    	if(Math.abs(diff[i]) <= 1){
	    		if(diff[i] == lastseen){
	    			l = i;
	    			lastseen = diff[i];
	    			//out.println("CASE 1");
	    		}
	    		else if(diff[i] != lastseen){
	    			if(i-l+2 > mLen){
	    				mLen = i-l+2;
	    			}
	    			if(diff[i]!=0){
	    				lastseen = diff[i];
	    			}
	    		//	out.println("CASE 2");
	    		}
	    	}
	    	else{
	    		l = i;
	    	}
	    //	out.println(l);
	    }
	    out.println(mLen);
	}
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out,true);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i =0;i<n;i++){
			arr[i] = sc.nextInt();
		}
		int[] diff = new int[n];
	    for(int i = 1;i<n;i++){
	    	diff[i] = arr[i]-arr[i-1];
	    	//out.println(diff[i]);
	    }
	    int l = 0,mLen = 1,lastseen = 0;
	    for(int i =1;i<n;i++){
	    	if(Math.abs(diff[i]) <= 1){
	    		if(diff[i] == lastseen && diff[i]!= 0){
	    			l = i;
	    			lastseen = diff[i];
	    			//out.println("CASE 1");
	    		}
	    		else if(diff[i] != lastseen || (diff[i] == 0)){
	    			if(i-l+2 > mLen){
	    				mLen = i-l+2;
	    			}
	    			if(diff[i]!=0){
	    				lastseen = diff[i];
	    			}
	    		//	out.println("CASE 2");
	    		}
	    	}
	    	else{
	    		l = i;
	    	}
	    //	out.println(l);
	    }
	    if(mLen<=n)
	    out.println(mLen);
	    else
	    out.println(n);
	}
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out,true);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i =0;i<n;i++){
			arr[i] = sc.nextInt();
		}
		int[] diff = new int[n];
	    for(int i = 1;i<n;i++){
	    	diff[i] = arr[i]-arr[i-1];
	    	//out.println(diff[i]);
	    }
	    int l = 0,mLen = 1,lastseen = 0;
	    for(int i =1;i<n;i++){
	    	if(Math.abs(diff[i]) <= 1){
	    		if(diff[i] == lastseen && diff[i]!= 0){
	    			l = i;
	    			lastseen = diff[i];
	    			//out.println("CASE 1");
	    		}
	    		else if(diff[i] != lastseen || (diff[i] == 0)){
	    			if(i-l+2 > mLen){
	    				mLen = i-l+2;
	    			}
	    			if(diff[i]!=0){
	    				lastseen = diff[i];
	    			}
	    		//	out.println("CASE 2");
	    		}
	    	}
	    	else{
	    		l = i;
	    	}
	    //	out.println(l);
	    }
	    out.println(mLen);
	}
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out,true);
		int n = sc.nextInt();
		long[] arr = new long[n];
		for(int i =0;i<n;i++){
			arr[i] = sc.nextLong();
		}
		long[] diff = new long[n];
	    for(int i = 1;i<n;i++){
	    	diff[i] = arr[i]-arr[i-1];
	    	//out.println(diff[i]);
	    }
	    int l = 0,mLen = 1;
	    long lastseen = 0;
	    for(int i =1;i<n;i++){
	    	if(Math.abs(diff[i]) <= 1){
	    		if(diff[i] == lastseen && diff[i]!= 0){
	    			l = i-1;
	    			lastseen = diff[i];
	    		//	out.println("CASE 1");
	    		//	out.println(l);
	    		}
	    		else if(diff[i] != lastseen || (diff[i] == 0)){
	    			if(i-l+1 > mLen){
	    				mLen = i-l+1;
	    			}
	    			if(diff[i]!=0){
	    				lastseen = diff[i];
	    			}
	    		//	out.println("CASE 2");
	    		//	out.println(diff[i]);
	    		}
	    	}
	    	else{
	    		l = i-1;
	    	}
	    //	out.println(l);
	    }
	    out.println(mLen);
	}
}


import java.util.*;
public class ApproximateConstantRange {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        int e[]=new int[n];
        int o[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=sc.nextInt();
            e[i]=o[i]=a[i];
        }
        int max=Integer.MIN_VALUE;
        int c=1;
        int d=1;
        for(int i=0;i<n;i++)
        {
            if(a[i]%2==0)
            {
                e[i]++;
            }
            else
                o[i]++;
        }
        for(int i=1;i<n;i++)
        {
            if(e[i-1]==e[i])c++;
            else
                c=1;
            if(o[i-1]==o[i])d++;
            else
                d=1;
            max=Math.max(max, c);
            max=Math.max(max, d);
        }
        System.out.println(max);
    }
}


import java.util.*;
public class AproximateConstntrange {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        int e[]=new int[n];
        int o[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=e[i]=o[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]%2==0)
            {
                o[i]++;
            }
            else
            {
                e[i]++;
            }
        }
        int c=1;
        int d=1;
        int max=Integer.MIN_VALUE;
        for(int i=1;i<n;i++)
        {
            if(o[i-1]==o[i])
                c++;
            else
                c=1;
            max=Math.max(max, c);
            if(e[i-1]==e[i])
                d++;
            else
                d=1;
            max=Math.max(max, d);

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


import java.util.Scanner;
public class Range
{
    public static void main(String arg[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        int o[]=new int[n];
        int e[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=o[i]=e[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]%2==0)
            o[i]++;
            else
            e[i]++;
        }
        int max=Integer.MIN_VALUE;
        int c=1;
        int d=1;
        for(int i=1;i<n;i++)
        {
            if(o[i-1]==o[i])c++;
            else c=1;
            max=Math.max(max,c);
            if(e[i-1]==e[i])d++;
            else d=1;
            max=Math.max(max,d);
        }
        System.out.println(max);
    }
}


//package com.codeforces.div2.B;

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

/**
 * @author Orestis
 * Problem Statement: http://codeforces.com/problemset/problem/602/B
 */
public class ConstantRange {

    private static int findMaxLength (int[] dataPoints, int[] aux, int n) {
        int left = 1;
        int result = 0;

        for (int i = 1; i <= n; ++i) {
            if (dataPoints[i] - 2 > 0){
                left = Math.max(left, aux[dataPoints[i] - 2] + 1);
            } else {
                left = Math.max(left, aux[dataPoints[i] + 2] + 1);
            }

//            if (dataPoints[i] + 2 <= 100000) {
//                left = Math.max(left, aux[dataPoints[i] + 2] + 1);
//            }

            aux[dataPoints[i]] = i;
            result = Math.max(result, i - left + 1);
        }

        return result;
    }

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

        int[] dataPoints = new int[100005];
        int[] aux = new int[100005];

        for (int i = 1; i <= 100000; ++i) aux[i] = 0;

        int numberOfDataPoints = inputReader.readInt();

        for (int i = 1; i <= numberOfDataPoints; ++i) {
            dataPoints[i] = inputReader.readInt();
        }

        outputWriter.print(findMaxLength(dataPoints, aux, numberOfDataPoints));
        outputWriter.close();
    }

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

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

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

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

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

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

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

    private static class OutputWriter
    {
        private final PrintWriter writer;

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

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

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

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

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

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

    }
}


//package com.codeforces.div2.B;

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

/**
 * @author Orestis
 * Problem Statement: http://codeforces.com/problemset/problem/602/B
 */
public class ConstantRange {

    private static int findMaxLength (int[] dataPoints, int[] aux, int n) {
        int left = 1;
        int result = 0;
        for (int i = 1; i <= n; ++i) {
            if (dataPoints[i] - 2 > 0){
                left = Math.max(left, aux[dataPoints[i] - 2] + 1);
            }

            if (dataPoints[i] + 2 <= 100000) {
                left = Math.max(left, aux[dataPoints[i] + 2] + 1);
            }

            aux[dataPoints[i]] = i;
            result = Math.max(result, i - left + 1);
        }

        return result;
    }

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

        int[] dataPoints = new int[100005];
        int[] aux = new int[100005];

        for (int i=1;i<=100000;++i) aux[i]=0;

        int numberOfDataPoints = inputReader.readInt();

        for (int i = 0; i < numberOfDataPoints; i++) {
            dataPoints[i] = inputReader.readInt();
        }

        outputWriter.print(findMaxLength(dataPoints, aux, numberOfDataPoints));
        outputWriter.close();
    }

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

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

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

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

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

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

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

    private static class OutputWriter
    {
        private final PrintWriter writer;

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

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

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

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

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

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

    }
}


//package com.codeforces.div2.B;

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

/**
 * @author Orestis
 * Problem Statement: http://codeforces.com/problemset/problem/602/B
 */
public class ConstantRange {

    private static int findMaxLength (int[] dataPoints, int[] aux, int n) {
        int left = 1;
        int result = 0;

        for (int i = 1; i <= n; ++i) {
            if (dataPoints[i] - 2 > 0){
                left = Math.max(left, aux[dataPoints[i] - 2] + 1);
            }

            if (dataPoints[i] + 2 <= 100000) {
                left = Math.max(left, aux[dataPoints[i] + 2] + 1);
            }

            aux[dataPoints[i]] = i;
            result = Math.max(result, i - left + 1);
        }

        return result;
    }

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

        int[] dataPoints = new int[100005];
        int[] aux = new int[100005];

        for (int i = 1; i <= 100000; ++i) aux[i] = 0;

        int numberOfDataPoints = inputReader.readInt();

        for (int i = 1; i <= numberOfDataPoints; ++i) {
            dataPoints[i] = inputReader.readInt();
        }

        outputWriter.print(findMaxLength(dataPoints, aux, numberOfDataPoints));
        outputWriter.close();
    }

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

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

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

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

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

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

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

    private static class OutputWriter
    {
        private final PrintWriter writer;

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

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

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

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

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

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

    }
}


//package com.codeforces.div2.B;

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

/**
 * @author Orestis
 * Problem Statement: http://codeforces.com/problemset/problem/602/B
 */
public class ConstantRange {

    private static int findMaxLength (int[] dataPoints, int[] aux, int n) {
        int left = 1;
        int result = 0;

        for (int i = 1; i <= n; ++i) {

            int point = dataPoints[i];

            if (point - 2 > 0){
                left = Math.max(left, aux[point - 2] + 1);
            }

            if (dataPoints[i] + 2 <= 100000) {
                left = Math.max(left, aux[point + 2] + 1);
            }

            aux[point] = i;
            result = Math.max(result, i - left + 1);
        }

        return result;
    }

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

        int[] dataPoints = new int[100005];
        int[] aux = new int[100005];

        int numberOfDataPoints = inputReader.readInt();

        for (int i = 1; i <= numberOfDataPoints; ++i) {
            dataPoints[i] = inputReader.readInt();
        }

        outputWriter.print(findMaxLength(dataPoints, aux, numberOfDataPoints));
        outputWriter.close();
    }

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

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

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

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

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

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

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

    private static class OutputWriter
    {
        private final PrintWriter writer;

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

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

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

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

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

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

    }
}


//package com.codeforces.div2.B;

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

/**
 * @author Orestis
 * Problem Statement: http://codeforces.com/problemset/problem/602/B
 */
public class ConstantRange {

    private static int findMaxLength (List<Integer> dataPoints, int start, int finish) {
        if (start == finish) {
            return 0;
        }
        int result = 1;
        for (int i = start; i < finish; i++) {
            int diff = dataPoints.get(i + 1) - dataPoints.get(start);
            if ( diff <= 1 && diff >= 0) {
                result += 1;
            }
        }

        return Math.max(result, findMaxLength(dataPoints, start + 1, finish));
    }

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

        List<Integer> dataPoints = new ArrayList<>();
        int numberOfDataPoints = inputReader.readInt();
        for (int i = 0; i < numberOfDataPoints; i++) {
            dataPoints.add(inputReader.readInt());
        }

        outputWriter.print(findMaxLength(dataPoints, 0, dataPoints.size() - 1));
        outputWriter.close();
    }

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

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

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

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

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

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

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

    private static class OutputWriter
    {
        private final PrintWriter writer;

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

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

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

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

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

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

    }
}