//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];

        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) {
        int result = 0;

        if (start == finish) {
            return 0;
        }

        int max = 0;
        int min = Integer.MAX_VALUE;

        for (int i = start; i <= finish; i++) {
            max = Math.max(max, dataPoints.get(i));
            min = Math.min(min, dataPoints.get(i));

            if ( max - min <= 1) {
                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();
        }

    }
}


//package com.codeforces.div2.B;

//import com.google.common.base.Stopwatch;

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) {
        int result = 0;

        if (start >= finish) {
            return 0;
        }

        int max = 0;
        int min = Integer.MAX_VALUE;

        for (int i = start; i <= finish; i++) {
            max = Math.max(max, dataPoints.get(i));
            min = Math.min(min, dataPoints.get(i));

            if ( max - min <= 1) {
                result += 1;
                start += 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());
        }
//        Stopwatch st = Stopwatch.createStarted();
        outputWriter.print(findMaxLength(dataPoints, 0, dataPoints.size() - 1));
//        st.stop();
//        System.out.println(st);
        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();
        }

    }
}


import java.util.*;

public class B {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] nums = new int[n];
		int[] difs = new int[n-1];

		for (int i = 0; i < n; i++) {
			nums[i] = in.nextInt();
		}

		int count = 0;
		int prev = 0;
		int j = 0;
		int max = 0;

		for (int i = 0; i < n-1; i++) {
			/*
			System.out.print("i: ");
			System.out.println(i);
			System.out.print("difs[i]: ");
			System.out.println(difs[i]);
			System.out.print("j: ");
			System.out.println(j);
			System.out.print("prev: ");
			System.out.println(prev);
			System.out.print("count: ");
			System.out.println(count);
			System.out.println("--------------------------------");
			*/
			if (difs[i] == 0) {
				count++;
			} else if (difs[i] == 1) {
				if (prev == 1) {
					i = j;
					count = 0;
					prev = 0;
				} else {
					prev = 1;
					j = i;
					count++;
				}
			} else {
				if (prev == -1) {
					i = j;
					count = 0;
					prev = 0;
				} else {
					prev = -1;
					j = i;
					count++;
				}
			}
			max = Math.max(max, count);
		}
		System.out.println(max+1);

	}

}


import java.util.*;

public class B {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] nums = new int[n];
		int[] difs = new int[n-1];

		for (int i = 0; i < n; i++) {
			nums[i] = in.nextInt();
		}

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

		int count = 0;
		int prev = 0;
		int j = 0;
		int max = 0;

		for (int i = 0; i < n-1; i++) {
			/*
			System.out.print("i: ");
			System.out.println(i);
			System.out.print("difs[i]: ");
			System.out.println(difs[i]);
			System.out.print("j: ");
			System.out.println(j);
			System.out.print("prev: ");
			System.out.println(prev);
			System.out.print("count: ");
			System.out.println(count);
			System.out.println("--------------------------------");
			*/
			if (difs[i] == 0) {
				count++;
			} else if (difs[i] == 1) {
				if (prev == 1) {
					i = j;
					count = 0;
					prev = 0;
				} else {
					prev = 1;
					j = i;
					count++;
				}
			} else {
				if (prev == -1) {
					i = j;
					count = 0;
					prev = 0;
				} else {
					prev = -1;
					j = i;
					count++;
				}
			}
			max = Math.max(max, count);
		}
		System.out.println(max+1);

	}

}


import java.util.*;

public class B {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] nums = new int[n];
		int[] difs = new int[n-1];

		for (int i = 0; i < n; i++) {
			nums[i] = in.nextInt();
		}

		for (int i = 0; i < n-1; i++) {
			difs[i] = nums[i+1]-nums[i];
			System.out.print(difs[i]);
			System.out.print(" ");
		}
		System.out.println();

		int count = 0;
		int prev = 0;
		int j = 0;
		int max = 0;

		for (int i = 0; i < n-1; i++) {
			/*
			System.out.print("i: ");
			System.out.println(i);
			System.out.print("difs[i]: ");
			System.out.println(difs[i]);
			System.out.print("j: ");
			System.out.println(j);
			System.out.print("prev: ");
			System.out.println(prev);
			System.out.print("count: ");
			System.out.println(count);
			System.out.println("--------------------------------");
			*/
			if (difs[i] == 0) {
				count++;
			} else if (difs[i] == 1) {
				if (prev == 1) {
					i = j;
					count = 0;
					prev = 0;
				} else {
					prev = 1;
					j = i;
					count++;
				}
			} else {
				if (prev == -1) {
					i = j;
					count = 0;
					prev = 0;
				} else {
					prev = -1;
					j = i;
					count++;
				}
			}
			max = Math.max(max, count);
		}
		System.out.println(max+1);

	}

}


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

public class Main {

    public static void main(String []arg) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int []a= new int[n];

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

        int Lmin = 0;

        int count = 0 ;

        int result = 0;

        for(int i = 0 ; i <a.length;++i) {

            if (a[Lmin] >= a[i]) Lmin = i;

            if (a[i] - a[Lmin]>2) {
                count =1;
                Lmin = i;
            } else if (a[i] - a[Lmin]==2||a[Lmin]-a[i]==1) {
                ++Lmin;
                count = i - Lmin + 1;
            } else {
                ++count ;
                result =Math.max(count,result);
            }

        }

        System.out.println(result);

    }
}


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

public class Main {

    public static void main(String []arg) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int []a= new int[n];

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

        int Lmin = 0;

        int count = 0 ;

        int result = 0;

        for(int i = 0 ; i <a.length;++i) {

            if (a[i] - a[Lmin]>2) {
                count =1;
                Lmin = i;
            } else if (a[i] - a[Lmin]==2||a[Lmin]-a[i]==1) {
                ++Lmin;
                count = i - Lmin + 1;
            } else {
                ++count ;

                result =Math.max(count,result);
            }

            if (a[Lmin] >= a[i]) Lmin = i;

        }

        System.out.println(result);

    }
}


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

public class Main {

    public static void main(String []arg) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int []a= new int[n];

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

        int count = 0 ;

        int result = 0;

        int Lmax = 0;
        int Lmin = 0;

        for(int i = 0 ; i <a.length;++i) {

            if(a[i]>=a[Lmax]) Lmax=i;
            if(a[i]<=a[Lmin]) Lmin =i;

            int disMax= Math.abs(a[Lmax]-a[i]);
            int disMin= Math.abs(a[Lmin]-a[i]);

            if(disMax<=1&&disMin<=1) {
                ++count;
                result = Math.max(count,result);
            } else {

                if(a[i]-a[Lmin]==2) {
                    count = i - Lmin;
                    if(i-Lmin>1) {
                        Lmin=Lmax-1;
                    }else{
                        Lmin = Lmax;
                    }

                }else if(a[Lmax]-a[i]==2) {
                    count = i-Lmax;
                    ++Lmax;
                    Lmin=i;

                } else{
                    count =1;
                    Lmax =i;
                    Lmin = i;
                }

            }

        }

        System.out.println(result);

    }
}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int currMin=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
		boolean ok=false;
		int l=0,pervMax=0;

		while(i<n) {

			if(minVal > a[i]) {
				minVal = a[i];
				currMin=i;
				pervMax = currMin;
			}
			if(maxVal <a[i] ) {
				if(pervMax <= currMin)
					pervMax = currMax;
				maxVal = a[i];
				currMax=i;
			}
			if(pervMax == currMin && a[i] > a[currMin]) {
				pervMax = i;
			}
			if(Math.abs(maxVal-minVal)>1) {

				max = Math.max(max, (i - l) );
				if ((a[currMax] - a[pervMax]) <= 1) {
					l = pervMax;
					minVal = a[l];
					currMin=l;
				} else if (currMax > currMin) {
					l = currMax;
					minVal = a[currMax];
				} else {
					l=currMin;
					currMax=currMin;
					maxVal=minVal;
				}
				ok=true;
			} else {
				ok=false;
			}

			i++;

		}
		if(!ok)
			max=Math.max(max, (i-l));
		System.out.println(max);
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
		boolean ok=false;
//		int start=0;
		while( i<n) {
			int pervMax = maxVal;
			minVal= Math.min(minVal, a[i]);
			maxVal= Math.max(maxVal, a[i]);
			if(Math.abs(maxVal-minVal) <=1) {
				i++;
				currMax++;
				ok=false;
			} else {
				ok=true;
				max = Math.max(currMax, max);
				if(maxVal-pervMax>1)
					currMax=0;
				else
					currMax=1;
				maxVal=Integer.MIN_VALUE;
			    minVal=pervMax;
			}
		}
		if(!ok)
			currMax--;
		System.out.println(Math.max(currMax, max));
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int currMin=0;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
		boolean ok=false;
		int l=0;
		while(i<n) {

			if(a[currMin] > a[i]) {
				currMin=i;
			}
			if(a[currMax] <a[i] ) {
				currMax=i;
			}
			if(Math.abs(a[currMax]-a[currMin])>1) {
				max = Math.max(max, (i - l) );
				if(currMin<currMax)
					for (; currMin <= currMax; currMin++) {
						if (Math.abs(a[currMax] - a[currMin]) <= 1) {
							l=currMin;
							break;
						}
					}
				else if(currMin>currMax) {
					for (; currMax <= currMin; currMax++) {
						if (Math.abs(a[currMax] - a[currMin]) <= 1) {
							l=currMax;
							break;
						}
					}
				}
				ok=true;
			} else {
				ok=false;
			}

			i++;

		}
		if(!ok)
			max=Math.max(max, (i-l));
		System.out.println(max);
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
//		int start=0;
		while( i<n) {
			int pervMax = maxVal;
			minVal= Math.min(minVal, a[i]);
			maxVal= Math.max(maxVal, a[i]);
			if(!(Math.abs(maxVal-minVal) <=1)) {
				max = Math.max(currMax, max);
				if(maxVal - pervMax<=1) {
					minVal=pervMax;
					currMax=1;
				}
				else {
					minVal=maxVal;
					currMax=0;
				}

			}
			currMax++;
			i++;
		}
		System.out.println(Math.max(currMax, max));
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
//		int start=0;
		while( i<n) {
			int pervMax = maxVal;
			minVal= Math.min(minVal, a[i]);
			maxVal= Math.max(maxVal, a[i]);
			if(Math.abs(maxVal-minVal) <=1) {
				i++;
				currMax++;
			} else {
				max = Math.max(currMax, max);
				if(maxVal-pervMax>1)
					currMax=0;
				else
					currMax=1;
				maxVal=Integer.MIN_VALUE;
			    minVal=pervMax;
			}
		}
		System.out.println(Math.max(currMax, max));
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int currMin=0;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
		boolean ok=false;
		int l=0;
		while(i<n) {

			if(a[currMin] > a[i]) {
				currMin=i;
			}
			if(a[currMax] <a[i] ) {
				currMax=i;
			}
			if(Math.abs(a[currMax]-a[currMin])>1) {
				max = Math.max(max, (i - l) );
				if(currMin<currMax)
				{
					int tmp = currMax;
					for (; currMin <= tmp; tmp--) {
						if (Math.abs(a[currMax] - a[tmp]) > 1) {
							break;
						}
					}
					currMin = tmp+1;
					l=currMin;
				}

				else if(currMin>currMax) {
					int tmp = currMin;
					for (; currMax <= tmp; tmp--) {
						if (Math.abs(a[currMin] - a[tmp]) > 1) {
							break;
						}
					}
					currMax = tmp+1;
					l=currMax;
				}
				ok=true;
			} else {
				ok=false;
			}

			i++;

		}
		if(!ok)
			max=Math.max(max, (i-l));
		System.out.println(max);
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
//		int start=0;
		while( i<n) {
			int pervMax = maxVal;
			minVal= Math.min(minVal, a[i]);
			maxVal= Math.max(maxVal, a[i]);
			if(Math.abs(maxVal-minVal) <=1) {
				i++;
				currMax++;
			} else {
				max = Math.max(currMax, max);
				maxVal=Integer.MIN_VALUE;
			    minVal=pervMax;
			    currMax=0;
			}
		}
		System.out.println(Math.max(currMax, max));
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
//		int start=0;
		while( i<n) {
			int pervMax = maxVal;
			minVal= Math.min(minVal, a[i]);
			maxVal= Math.max(maxVal, a[i]);
			if(Math.abs(maxVal-minVal) <=1) {
				i++;
				currMax++;
			} else {
				max = Math.max(currMax, max);
				if(maxVal-pervMax>1) {
					minVal=maxVal;
					currMax=0;
				} else {
					minVal=pervMax;
				    currMax=1;
				}

			}
		}
		System.out.println(Math.max(currMax, max));
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
//		int start=0;
		while( i<n) {
			int pervMax = maxVal;
			minVal= Math.min(minVal, a[i]);
			maxVal= Math.max(maxVal, a[i]);
			if(Math.abs(maxVal-minVal) <=1) {
				i++;
				currMax++;
			} else {
				max = Math.max(currMax, max);
				maxVal=Integer.MIN_VALUE;
			    minVal=pervMax;
			    currMax=1;
			}
		}
		System.out.println(Math.max(currMax, max));
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int currMin=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
		boolean ok=false;
		int l=0,pervMax=0;
		while( i<n) {

			if(minVal > a[i]) {
				minVal = a[i];
				currMin=i;
				pervMax = currMin;
			}
			if(maxVal <a[i] ) {
				if(pervMax <= currMin)
					pervMax = currMax;
				maxVal = a[i];
				currMax=i;
			}
			if(pervMax == currMin && a[i] > a[currMin]) {
				pervMax = i;
			}
			if(Math.abs(maxVal-minVal)>1) {

				max = Math.max(max, (i - l) );
				if ((a[currMax] - a[pervMax]) <= 1) {
					l = pervMax;
					minVal = a[l];
					currMin=l;
				} else if (currMax > currMin) {
					l = currMax;
					minVal = a[currMax];
				}
				ok=true;
			} else {
				ok=false;
			}

			i++;

		}
		if(!ok)
			max=Math.max(max, (i-l));
		System.out.println(max);
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int currMin=0;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
		boolean ok=false;
		int l=0;
		while(i<n) {

			if(a[currMin] > a[i]) {
				currMin=i;
			}
			if(a[currMax] <a[i] ) {
				currMax=i;
			}
			if(Math.abs(a[currMax]-a[currMin])>1) {
				max = Math.max(max, (i - l) );
				if(currMin<currMax)
				{
					int tmp = currMax;
					for (; currMin <= tmp; tmp--) {
						if (Math.abs(a[currMax] - a[tmp]) > 1) {
							break;
						}
					}
					currMin = tmp+1;
					l=currMin;
				}

				else if(currMin>currMax) {
					int tmp = currMin;
					for (; currMax <= tmp; tmp--) {
						if (Math.abs(a[currMin] - a[tmp]) > 1) {
							break;
						}
						currMax = tmp+1;
						l=currMax;
					}
				}
				ok=true;
			} else {
				ok=false;
			}

			i++;

		}
		if(!ok)
			max=Math.max(max, (i-l));
		System.out.println(max);
		scanner.close();
	}

}


import java.util.Scanner;

public class B602 {

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

		int []a = new int[n];

		int currMax=0;
		int maxVal=Integer.MIN_VALUE;
		int minVal=Integer.MAX_VALUE;
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		int i=0;
//		int start=0;
		while( i<n) {
			int pervMax = maxVal;
			minVal= Math.min(minVal, a[i]);
			maxVal= Math.max(maxVal, a[i]);
			if(Math.abs(maxVal-minVal) <=1) {
				currMax++;
			} else {
				max = Math.max(currMax, max);

				maxVal=Integer.MIN_VALUE;
				currMax=1;
				if(maxVal - pervMax<=1) {
					minVal=pervMax;

				}
				else {
					minVal=Integer.MAX_VALUE;

				}

			}
			i++;
		}
		System.out.println(Math.max(currMax, max));
		scanner.close();
	}

}


import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	Scanner in;
	int n, ans;
	int[] arr;
	MultiIntegerSet s;

	Main() {
		read();
		solve();
	}

	private void read() {
		in = new Scanner(System.in);
		n = in.nextInt();
		arr = new int[n];
		for (int i = 0; i < n; ++i) {
			arr[i] = in.nextInt();
		}
		s = new MultiIntegerSet(100002);
	}

	private void solve() {
		int l = 0, r = 0;
		s.insert(arr[0]);
		ans = Math.max(ans, r - l + 1);
		++r;
		s.insert(arr[r]);
		while (r < n && l < n) {
			if (s.getMax() - s.getMin() > 1) {
				s.remove(arr[l]);
				++l;
			} else {
				if (r < n) {

					ans = Math.max(ans, r - l + 1);
					++r;
					if (r < n) {
					s.insert(arr[r]);
					}
				}
			}
		}
		System.out.println(ans);
	}

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

	static class MultiIntegerSet {
		private Set<Integer> s;
		private int[] fre;

		MultiIntegerSet(int maxElementValue) {
			s = new HashSet<Integer>();
			fre = new int[maxElementValue];
		}

		public void insert(int value) {
			++fre[value];
			s.add(value);
		}

		public void remove(int value) {
			int f = getFre(value);
			f -= 1;
			if (f == 0) {
				s.remove(value);
			}
			fre[value] = f;
		}

		public int getMax() {
			return Collections.max(s);
		}

		public int getMin() {
			return Collections.min(s);
		}

		public int getFre(int value) {
			return fre[value];
		}

		public boolean contains(int value) {
			return s.contains(value);
		}
	}

}


import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	Scanner in;
	int n, ans;
	int[] arr;
	MultiIntegerSet s;

	Main() {
		read();
		solve();
	}

	private void read() {
		in = new Scanner(System.in);
		n = in.nextInt();
		arr = new int[n];
		for (int i = 0; i < n; ++i) {
			arr[i] = in.nextInt();
		}
		s = new MultiIntegerSet(100002);
	}

	private void solve() {
		int l = 0, r = 0;
		s.insert(arr[0]);
		ans = Math.max(ans, r - l + 1);
		++r;
		while (r < n && l < n) {
			if (s.getMax() - s.getMin() > 1) {
				s.remove(arr[l]);
				++l;
			} else {
				if (r < n) {
					ans = Math.max(ans, r - l + 1);
					++r;
					if (r < n) {
					s.insert(arr[r]);
					}
				}
			}
		}
		System.out.println(ans);
	}

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

	static class MultiIntegerSet {
		private Set<Integer> s;
		private int[] fre;

		MultiIntegerSet(int maxElementValue) {
			s = new HashSet<Integer>();
			fre = new int[maxElementValue];
		}

		public void insert(int value) {
			++fre[value];
			s.add(value);
		}

		public void remove(int value) {
			int f = getFre(value);
			f -= 1;
			if (f == 0) {
				s.remove(value);
			}
			fre[value] = f;
		}

		public int getMax() {
			return Collections.max(s);
		}

		public int getMin() {
			return Collections.min(s);
		}

		public int getFre(int value) {
			return fre[value];
		}

		public boolean contains(int value) {
			return s.contains(value);
		}
	}

}


import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	Scanner in;
	int n, ans;
	int[] arr;
	MultiIntegerSet s;

	Main() {
		read();
		solve();
	}

	private void read() {
		in = new Scanner(System.in);
		n = in.nextInt();
		arr = new int[n];
		for (int i = 0; i < n; ++i) {
			arr[i] = in.nextInt();
		}
		s = new MultiIntegerSet(100002);
	}

	private void solve() {
		int l = 0, r = 0;
		s.insert(arr[0]);
		ans = Math.max(ans, r - l + 1);
		++r;
		while (r < n && l < n) {
			if (s.getMax() - s.getMin() > 1) {
				s.remove(arr[l]);
				++l;
			} else {
				ans = Math.max(ans, r - l + 1);
				++r;
				if (r < n)
					s.insert(arr[r]);
			}
		}
		System.out.println(ans);
	}

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

	static class MultiIntegerSet {
		private Set<Integer> s;
		private int[] fre;

		MultiIntegerSet(int maxElementValue) {
			s = new HashSet<Integer>();
			fre = new int[maxElementValue];
		}

		public void insert(int value) {
			++fre[value];
			s.add(value);
		}

		public void remove(int value) {
			int f = getFre(value);
			f -= 1;
			if (f == 0) {
				s.remove(value);
			}
			fre[value] = f;
		}

		public int getMax() {
			return Collections.max(s);
		}

		public int getMin() {
			return Collections.min(s);
		}

		public int getFre(int value) {
			return fre[value];
		}

		public boolean contains(int value) {
			return s.contains(value);
		}
	}

}


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

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

    static class BApproximatingAConstantRange {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) a[i] = in.nextInt();
            BApproximatingAConstantRange.RMQ rmq = new BApproximatingAConstantRange.RMQ(a);
            int low = 1;
            int high = n;
            while (low <= high) {
                int mid = low + high >> 1;
                boolean found = false;
                for (int l = 0, r = mid - 1; r < n; ++l, ++r) {
                    int min = rmq.minquery(l, r);
                    int max = rmq.maxquery(l, r);
                    if (max - min <= 1) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            out.println(high);
        }

        static class RMQ {
            int[] vs;
            int[][] minlift;
            int[][] maxlift;

            public RMQ(int[] vs) {
                this.vs = vs;
                int n = vs.length;
                int maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(n)) + 2;
                minlift = new int[maxlog][n];
                maxlift = new int[maxlog][n];
                for (int i = 0; i < n; i++)
                    minlift[0][i] = maxlift[0][i] = vs[i];
                int lastRange = 1;
                for (int lg = 1; lg < maxlog; lg++) {
                    for (int i = 0; i < n; i++) {
                        minlift[lg][i] = Math.min(minlift[lg - 1][i], minlift[lg - 1][Math.min(i + lastRange, n - 1)]);
                        maxlift[lg][i] = Math.max(maxlift[lg - 1][i], maxlift[lg - 1][Math.min(i + lastRange, n - 1)]);
                    }
                    lastRange *= 2;
                }
            }

            public int maxquery(int low, int hi) {
                int range = hi - low + 1;
                int exp = Integer.highestOneBit(range);
                int lg = Integer.numberOfTrailingZeros(exp);
                return Math.max(maxlift[lg][low], maxlift[lg][hi - exp + 1]);
            }

            public int minquery(int low, int hi) {
                int range = hi - low + 1;
                int exp = Integer.highestOneBit(range);
                int lg = Integer.numberOfTrailingZeros(exp);
                return Math.min(minlift[lg][low], minlift[lg][hi - exp + 1]);
            }

        }

    }

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

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

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

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

    }
}


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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) a[i] = in.nextInt();

            int l = 0, r = 1;
            int ans = 0;

            int min = a[0], minCount = 1;
            int max = a[0], maxCount = 1;

            while (r < n) {
                int el = a[r];
                int curMin = min, curMax = max;
                if (el > max) {
                    max = el;
                } else if (el < min) {
                    min = el;
                } else {
                    if (el == min) {
                        ++minCount;
                    } else {
                        ++maxCount;
                    }
                }
                if (max - min > 1) {
                    if (el == min) {
                        while (maxCount > 0) {
                            if (a[l] == curMax) {
                                --maxCount;
                            } else if (a[l] == curMin) {
                                --minCount;
                            }
                            ++l;
                        }
                        max = curMin;
                        maxCount = minCount;
                        minCount = 1;
                    } else {
                        while (minCount > 0) {
                            if (a[l] == curMin) {
                                --minCount;
                            } else if (a[l] == curMax) {
                                --maxCount;
                            }
                            ++l;
                        }
                        min = curMax;
                        minCount = maxCount;
                        maxCount = 1;
                    }
                }
                ans = Math.max(ans, r - l + 1);
                ++r;
            }
            out.println(ans);
        }

    }

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

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

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

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

    }
}


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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) { //i hate cf sometimes
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) a[i] = in.nextInt();

            int l = 0, r = 1;
            int ans = 0;

            int min = a[0], minCount = 1;
            int max = a[0], maxCount = 1;

            while (r < n) {
                int el = a[r];
                int curMin = min, curMax = max;
                if (el > max) {
                    max = el;
                } else if (el < min) {
                    min = el;
                } else {
                    if (el == min) {
                        ++minCount;
                    } else {
                        ++maxCount;
                    }
                }
                if (max - min > 1) {
                    if (el == min) {
                        while (maxCount > 0) {
                            if (a[l] == curMax) {
                                --maxCount;
                            } else if (a[l] == curMin) {
                                --minCount;
                            }
                            ++l;
                        }
                        max = curMin;
                        maxCount = minCount;
                        minCount = 1;
                    } else {
                        while (minCount > 0) {
                            if (a[l] == curMin) {
                                --minCount;
                            } else if (a[l] == curMax) {
                                --maxCount;
                            }
                            ++l;
                        }
                        min = curMax;
                        minCount = maxCount;
                        maxCount = 1;
                    }
                }
                ans = Math.max(ans, r - l + 1);
                ++r;
            }
            out.println(ans);
        }

    }

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

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

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

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

    }
}


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

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

    static class B602 {
        int n;
        int[] a;

        private boolean contains(int size) {
            for (int start = 0; start < n - size; start++) {
                HashSet<Integer> set = new HashSet<>();
                for (int i = start; i <= start + size; i++) {
                    set.add(a[i]);
                }
                if (set.size() == 2) {
                    int[] mM = new int[2];
                    int i = 0;
                    for (int k : set) {
                        mM[i++] = k;
                    }
                    if (Math.abs(mM[0] - mM[1]) <= 1) {
                        return true;
                    }
                }
            }
            return false;
        }

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

            n = in.nextInt();
            a = new int[n];

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

            int low = 1;
            int high = n;

            while (low <= high) {
                int mid = (low + high + 1) / 2;
                if (contains(mid)) {
                    low = mid;
                } else {
                    high = mid;
                }
                if (low == high - 1) {
                    break;
                }
            }

            int ans;

            if (low == high - 1 && contains(high)) {
                ans = high;
            } else {
                ans = low;
            }

            out.println(ans + 1);

        }

    }

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

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

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

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

    }
}


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

public class CodeforcesB602 {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n=Integer.parseInt(bf.readLine());
		int []a=new int [n];
		StringTokenizer ns =new StringTokenizer(bf.readLine());
		for(int i=0;i<n;i++)
			a[i]=Integer.parseInt(ns.nextToken());

		int result=0;
		for(int i=0;i<n;i++){
			int j,r=0,max=a[i],min=a[i];
			for(j=i;j<n;j++){
				if(a[j]>max)
					max=a[j];
				if(a[j]<min)
					min=a[j];
				if(max-min<=1)
					r++;
				else
					break;
			}
			if(r>result)
				result=r;
		}

		out.println(result);
		out.close();
	}

}


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

public class CodeforcesB602 {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n=Integer.parseInt(bf.readLine());
		int []a=new int [n];
		StringTokenizer ns =new StringTokenizer(bf.readLine());
		for(int i=0;i<n;i++)
			a[i]=Integer.parseInt(ns.nextToken());

		int result=0;
		for(int i=0;i<n;i++){
			int j,r=0,max=a[i],min=a[i];
			for(j=i;j<n;j++){
				if(a[j]>max)
					max=a[j];
				if(a[j]<min)
					min=a[j];
				if(max-min<=1)
					r++;
				else
					break;
			}
			if(r>result)
				result=r;
			i=j-1;
		}

		out.println(result+1);
		out.close();
	}

}


// package CF;

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

public class B602 {

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = in.nextInt();
		int cnt[] = new int[(int) 1e6 + 5];
		TreeSet<Integer> ts = new TreeSet<>();
		cnt[arr[0]]++;
		ts.add(arr[0]);
		int res = 0;
		for (int l = 0, r = 1; l < n; l++) {
			while (r < n) {
				int max = Math.max(arr[r], ts.last());
				int min = Math.min(arr[r], ts.first());
				if(max - min > 1)
					break;
				ts.add(arr[r]);
				cnt[arr[r]]++;
				r++;
			}
//			System.err.println(l + " " + r);
//			System.err.println(ts.toString());
			res = Math.max(res, r - l);
			cnt[arr[l]]--;
			if(cnt[arr[l]] == 0)
				ts.remove(arr[l]);
		}
		System.out.println(res);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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


n = int(input())
a = list(map(int, input().split(" ")))
l = [3, 2, 1, 3]
rest = 0
last = 0
for i in range(n):
    if a[i] == 0:
        rest += 1
        last = 0
    elif a[i] == 3:
        last = l[last]
    else:
        if last == a[i]:
            rest += 1
            last = 0
        else:
            last = a[i]

print(rest)


n = int(input())
a = list(map(int, input().split(" ")))
l = [3, 2, 1, 3]
rest = 0
last = 0
for i in range(n):
    if a[i] == 0:
        rest += 1
        last = 0
    elif a[i] == 3:
        last = l[last]
    else:
        if last == a[i]:
            rest += 1
            last = 1
        else:
            last = a[i]

print(rest)


n = int(input())
a = list(map(int, input().split(" ")))
l = [4, 2, 3, 4]
rest = 0
last = 0
for i in range(n):
    if a[i] == 0:
        rest += 1
        last = 0
    elif a[i] == 3:
        last = l[last]
    else:
        if last == a[i]:
            rest += 1
            last = 1
        else:
            last = a[i]

print(rest)


"""
    http://codeforces.com/problemset/problem/698/A

"""
from sys import stdin, stdout
from array import array

def solve(days):
    rest_num = 0
    prev_act = 3
    for i in range(0, len(days)-1):
        cur_act = days[i]
        next_act = days[i+1]
        # stdout.write(str(cur_act))
        if cur_act == 0 or prev_act == cur_act:
            prev_act = 0
            rest_num += 1
        elif prev_act != cur_act and cur_act != 3:
            prev_act = cur_act
        else:  # cur_act == 3
            if prev_act in (1, 2):
                prev_act = prev_act % 2 + 1
            else:
                if next_act in (1, 2):
                    prev_act = next_act % 2 + 1

        # rest_num += 1
    return rest_num

if __name__ == "__main__":
    use_stdio = True
    days = []
    if use_stdio:
        length = int(stdin.readline())
        days = array('i', list(map(int, stdin.readline().split()))+[3])
        stdout.write(str(solve(days)))
    else:
        with open('input', 'r') as fin, open('output', 'w') as fout:
            length = int(fin.readline())
            days = array('i', list(map(int, fin.readline().split()))+[3])
            fout.write(str(solve(days)))


"""
    http://codeforces.com/problemset/problem/698/A

"""
from sys import stdin, stdout
from array import array

def solve(days):
    rest_num = 0
    prev_act = 0
    for i in range(0, len(days)-1):
        cur_act = days[i]
        next_act = days[i+1]
        # stdout.write(str(cur_act))
        if cur_act == 0 or prev_act == cur_act:
            prev_act = 0
            rest_num += 1
        elif prev_act != cur_act and cur_act != 3:
            prev_act = cur_act
        else:  # cur_act == 3
            if prev_act in (1, 2):
                prev_act = prev_act % 2 + 1
            else:
                if next_act in (1, 2):
                    prev_act = next_act % 2 + 1

        # rest_num += 1
    return rest_num

if __name__ == "__main__":
    use_stdio = True
    days = []
    if use_stdio:
        length = int(stdin.readline())
        days = array('i', list(map(int, stdin.readline().split()))+[3])
        stdout.write(str(solve(days)))
    else:
        with open('input', 'r') as fin, open('output', 'w') as fout:
            length = int(fin.readline())
            days = array('i', list(map(int, fin.readline().split()))+[3])
            fout.write(str(solve(days)))


"""
    http://codeforces.com/problemset/problem/698/A

"""
from sys import stdin, stdout
from array import array

def solve(days):
    rest_num = 0
    prev_act = 3
    for i in range(0, len(days)-1):
        cur_act = days[i]
        next_act = days[i+1]
        # stdout.write(str(cur_act))
        if cur_act == 0 or prev_act == cur_act:
            prev_act = 0
            rest_num += 1
        elif prev_act != cur_act and cur_act != 3:
            prev_act = cur_act
        else:  # cur_act == 3
            if prev_act in (1, 2):
                prev_act = prev_act % 2 + 1
            else:
                if next_act in (1, 2):
                    prev_act = next_act % 2 + 1

        # rest_num += 1
    return rest_num

if __name__ == "__main__":
    use_stdio = True
    days = []
    if use_stdio:
        length = int(stdin.readline())
        days = array('i', list(map(int, stdin.readline().split())).append(3))
        stdout.write(str(solve(days)))
    else:
        with open('input', 'r') as fin, open('output', 'w') as fout:
            length = int(fin.readline())
            days = array('i', list(map(int, fin.readline().split()))+[3])
            fout.write(str(solve(days)))


# def helper(n, curr='.'):
#     if n == 0:
#         return 0
#     elif a[n-1] == 0:
#         return 1+helper(n-1, '.')
#     elif a[n-1] == 1:
#         if curr=='g' or curr=='.':
#             return helper(n-1, 'c')
#         else:
#             return 1+helper(n-1, 'c')
#     elif a[n-1] == 2:
#         if curr=='.' or curr=='c':
#             return helper(n-1, 'g')
#         else:
#             return 1+helper(n-1, 'g')
#     else:
#         if curr=='.':
#             return min(helper(n-1, 'c'), helper(n-1, 'g'))
#         elif curr=='c':
#             return min(1+helper(n-1, 'c'), helper(n-1, 'g'))
#         else:
#             return min(1+helper(n-1, 'g'), helper(n-1, 'c'))

n = int(input())
a = list(map(int, input().split()))
last = a[0]
res = 0
if last == 0:
    res += 1
for i in range(1, n):
    if (a[i] and a[i] != last) or (a[i] == 3):
        if a[i] == 3:
            if last == 1:
                a[i] = 2
            elif last == 2:
                a[i] = 1
    else:
        a[i] = 0
        res += 1
    last = a[i]
print(res)


def helper(n, curr='.'):
    if n == 0:
        return 0
    elif a[n-1] == 0:
        return 1+helper(n-1, '.')
    elif a[n-1] == 1:
        if curr=='g' or curr=='.':
            return helper(n-1, 'c')
        else:
            return 1+helper(n-1, 'c')
    elif a[n-1] == 2:
        if curr=='.' or curr=='c':
            return helper(n-1, 'g')
        else:
            return 1+helper(n-1, 'g')
    else:
        if curr=='.':
            return min(helper(n-1, 'c'), helper(n-1, 'g'))
        elif curr=='c':
            return min(1+helper(n-1, 'c'), helper(n-1, 'g'))
        else:
            return min(1+helper(n-1, 'g'), helper(n-1, 'c'))

n = int(input())
a = list(map(int, input().split()))
print(helper(n, '.'))


"""Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:

on this day the gym is closed and the contest is not carried out;
on this day the gym is closed and the contest is carried out;
on this day the gym is open and the contest is not carried out;
on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

Input
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations.

The second line contains the sequence of integers a 1, a 2, ..., a n (0 ≤ a i ≤ 3) separated by space, where:

a i equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
a i equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
a i equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
a i equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:

to do sport on any two consecutive days,
to write the contest on any two consecutive days.
Examples
inputCopy
4
1 3 2 0
outputCopy
2
inputCopy
7
1 3 3 2 1 2 3
outputCopy
0
inputCopy
2
2 2
outputCopy
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.

In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.

In the third test Vasya can do sport either on a day num"""

n=int(input())
arr=list(map(int,input().split()))
d=[0 for i in range(n)]
for i in range(n):
    if arr[i]==0:
        d[i]+=1
    if i !=0:

        if arr[i]==arr[i-1] and arr[i]!=3 and arr[i]!=0:
            d[i]+=1
            arr[i]=0
        elif arr[i]==3 and arr[i-1]==1:
            arr[i]=2

        elif arr[i]==3 and arr[i-1]==2:
            arr[i]=1

        d[i]+=d[i-1]

print(d[n-1])


"""Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:

on this day the gym is closed and the contest is not carried out;
on this day the gym is closed and the contest is carried out;
on this day the gym is open and the contest is not carried out;
on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

Input
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations.

The second line contains the sequence of integers a 1, a 2, ..., a n (0 ≤ a i ≤ 3) separated by space, where:

a i equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
a i equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
a i equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
a i equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:

to do sport on any two consecutive days,
to write the contest on any two consecutive days.
Examples
inputCopy
4
1 3 2 0
outputCopy
2
inputCopy
7
1 3 3 2 1 2 3
outputCopy
0
inputCopy
2
2 2
outputCopy
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.

In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.

In the third test Vasya can do sport either on a day num"""

n=int(input())
arr=list(map(int,input().split()))
d=[0 for i in range(n)]
for i in range(n):
    if arr[i]==0:
        d[i]+=1
    if i !=0:
        if arr[i]==arr[i-1] and arr[i]!=3 and arr[i]!=0:
            d[i]+=1
            arr[i]=0
        if arr[i]==3 and arr[i-1]==1:
            arr[i]=2
        elif arr[i]==3 and arr[i-1]==2:
            arr[i]==1
        d[i]+=d[i-1]

print(d[n-1])


days = int(input())

activities = [int(x) for x in input().split()]

free_days = 0
last_activity = 0
both_count = 0
for activity in activities:
    if activity == 3:
        both_count += 1
    else:
        if activity == 0:
            free_days += 1
            last_activity = 0
        elif last_activity != 0 and \
             (both_count % 2 == 0 and last_activity == activity or \
             both_count % 2 != 0 and last_activity != activity):
            free_days += 1
            last_activity = 0
        else:
            last_activity = activity
        both_count = 0

print(free_days)


days = int(input())

activities = [int(x) for x in input().split()]

free_days = 0
last_activity = 0
both_count = 0
for activity in activities:
    if activity == 0:
        free_days += 1
        last_activity = activity
        both_count = 0
    elif activity == 3:
        both_count += 1
    else:
        if both_count % 2 == 0 and last_activity == activity or \
           both_count % 2 != 0 and last_activity != activity:
            free_days += 1
        both_count = 0
        last_activity = activity

print(free_days)


"Codeforces Round #363 (Div. 1)"
"A. Vacations"
y=int(input())
al=input().split()
m=list(map(int,al))
l=0
z=0
m.append(0)
for i in range(y):
    #print(l,m[i],z)
    if m[i]==0:
        z+=1
        l=0
        continue
    if l==0:
        if m[i]==m[i+1] and (m[i]==1 or m[i]==2):
            z+=1
            l=0
            continue
        elif m[i]==3 and m[i]==m[i+1]:
            l=3
            continue
        elif m[i]==3:
            l=3-m[i+1]
            continue
        l=m[i]
    elif m[i]==l and m[i]!=3:
        z+=1
        l=0
    elif l==3:
        if m[i+1]==2:
            l=1
        elif m[i+1]==1:
            l=2
    elif m[i]==3 or m[i]!=l:
        l=3-l

#print(l,m[-2],z)
print(z)


"Codeforces Round #363 (Div. 1)"
"A. Vacations"
y=int(input())
al=input().split()
m=list(map(int,al))
l=0
z=0
m.append(0)
for i in range(y):
    #print(l,m[i],z)
    if m[i]==0:
        z+=1
        l=0
        continue
    if l==0:
        if m[i]==m[i+1] and (m[i]==1 or m[i]==2):
            m[i+1]=0
            continue
        elif m[i]==3 and m[i]==m[i+1]:
            l=3
            continue
        elif m[i]==3:
            l=3-m[i+1]
            continue
        l=m[i]
    elif m[i]==l and m[i]!=3:
        z+=1
        l=0
    elif l==3:
        if m[i+1]==2:
            l=1
        elif m[i+1]==1:
            l=2
    elif m[i]==3 or m[i]!=l:
        l=3-l

#print(l,m[-2],z)
print(z)


"Codeforces Round #363 (Div. 1)"
"A. Vacations"
y=int(input())
al=input().split()
m=list(map(int,al))
l=0
z=0
m.append(0)
for i in range(y):
    #print(l,m[i])
    if m[i]==0:
        z+=1
        l=0
        continue
    if l==0:
        if m[i]==m[i+1] and (m[i]==1 or m[i]==2):
            z+=1
            continue
        l=m[i]
    elif m[i]==l:
        z+=1
        l=0
    elif m[i]==3 or m[i]!=l:
        l=3-l
#print(l,m[-2])
print(z)


"Codeforces Round #363 (Div. 1)"
"A. Vacations"
y=int(input())
al=input().split()
m=list(map(int,al))
l=0
z=0
m.append(0)
for i in range(y):
    #print(l,m[i])
    if m[i]==0:
        z+=1
        l=0
        continue
    if l==0:
        if m[i]==m[i+1] and (m[i]==1 or m[i]==2):
            z+=1
            continue
        elif m[i]==3:
            l=3
            continue
        l=m[i]
    elif m[i]==l:
        z+=1
        l=0
    elif m[i]==3 or m[i]!=l:
        l=3-l
    elif l==3:
        if m[i+1]==2:
            l=1
        elif m[i+1]==1:
            l=2
#print(l,m[-2])
print(z)


for t in range(1):
    n=int(input())
    arr=list(map(int,input().split()))
    prev=arr[0]
    if prev==0:
        count=1
    else:
        count=0
    for ele in range(1,n):
        i=arr[ele]
        if i==0:
            count+=1
            prev=0
            continue
        elif i==1:
            if prev==1:
                prev=0
                count+=1
                continue
            else:
                prev=1
                continue
        elif i==2:
            if prev==2:
                prev=0
                count+=1
                continue
            else:
                prev=2
                continue
        elif i==3:
            if prev==1:
                prev=2
                continue
            elif prev==2:
                prev=1
                continue
            else:
                prev=0
                continue
    print(count)


'''input
7
1 3 3 2 1 2 3
'''
import numpy as np
from sys import stdin,stdout
read = lambda: map(int,stdin.readline().split())
I = lambda: stdin.readline()

n = int(I())
arr = tuple(read())
memo = {}
poss = [[0],[0,1],[0,2],[0,1,2]]
# dp = [[10**6 for i in range(4)] for i in range(n+1)]
dp = np.ones((n+1,3),np.uint32)*10**6
dp[n][:] = 0

for i in range(n-1,-1,-1):
	for last in range(3):
		for p in poss[arr[i]]:
			# print(last,p,1 if ((last and p) or p==0) else 0)
			dp[i][last] = min(dp[i][last],(1 if ((last & p) or p==0) else 0) + dp[i+1][p])
print(dp[0][0])
# print(dp)


'''input
7
1 3 3 2 1 2 3
'''
# import numpy as np
from sys import stdin,stdout
read = lambda: map(int,stdin.readline().split())
I = lambda: stdin.readline()

n = int(I())
arr = tuple(read())
memo = {}
poss = [[0],[0,1],[0,2],[0,1,2]]
dp = [[10**6 for i in range(3)] for i in range(n+1)]
dp[n] = [0,0,0]
# print(dp)
for i in range(n-1,-1,-1):
	for last in range(3):
		for p in poss[arr[i]]:
			# print(last,p,1 if ((last and p) or p==0) else 0)
			dp[i][last] = min(dp[i][last],(1 if ((last & p) or p==0) else 0) + dp[i+1][p])
print(dp[0][0])
# print(dp)


n = int(input())

last = -1

a = list(map(int, input().split()))

ans = 0

for x in a:
    if x == 0:
        last = -1
        ans += 1
    elif x < 3:
        if last == x:
            last = -1
            ans += 1
            continue
        last = x
    else:
        if last == 1:
            last = 2
        elif last == 2:
            last = 1
        else:
            last = -1

print(ans)


n = int(input())

last = -1

a = list(map(int, input().split()))

ans = 0

for x in a:
    if x == 0:
        last = -1
        ans += 1
    elif x < 3:
        ans += last == x
        last = x
    else:
        if last == 1:
            last = 2
        elif last == 2:
            last = 1
        else:
            last = -1

print(ans)


input()
days = input().split()
last = '0'
counter = 0
for day in days:
    if last == day or day == '0':
        counter += 1
        last = '0'
    else:
        if day != '3':
            last = day
        else:
            if last == '1':
                last = '2'
            else:
                last = '1'
print(counter)


n = int(input())
days = input().split()
last = '0'
counter = 0
for i in range(n):
    if last == days[i] or days[i] == '0':
        counter += 1
        last = '0'
    else:
        if days[i] != '3':
            last = days[i]
        else:
            if last == '1':
                last = '2'
            elif last == '2':
                last = '1'
            else:
                if i < n - 1:
                    if days[i+1] == '1':
                        last = '2'
                    elif days[i+1] == '2':
                        last = '1'
print(counter)


n = int(input())
a = [int(i) for i in input().split()]

dp = [{'rest': 0, 'contest': 0, 'gym': 0} for i in range(n)]

for i in range(n):
    if a[i] == 1 or a[i] == 3:
        dp[i]['contest'] = (dp[i - 1]['gym'] | dp[i - 1]['rest'])
        if i == 0:
            dp[i]['contest'] = 1
    if a[i] == 2 or a[i] == 3:
        dp[i]['gym'] = (dp[i - 1]['contest'] | dp[i - 1]['rest'])
        if i == 0:
            dp[i]['gym'] == 1

    if (dp[i]['contest'] | dp[i]['gym']) == 0:
        dp[i]['rest'] = 1

count = 0
for i in range(n):
    count += dp[i]['rest']

print(count)


n = int(input())
a = [int(i) for i in input().split()]

dp = [{'rest': False, 'contest': False, 'gym': False} for i in range(n)]

for i in range(n):
    if a[i] == 1:
        if i == 0:
            dp[i]['contest'] = True
        else:
            dp[i]['contest'] = (dp[i - 1]['gym'] or dp[i - 1]['rest'])

    if a[i] == 2:
        if i == 0:
            dp[i]['gym'] = True
        else:
            dp[i]['gym'] = (dp[i - 1]['contest'] or dp[i - 1]['rest'])

    if a[i] == 3:
        if i == 0:
            dp[i]['contest'] = True
        else:
            if dp[i - 1]['contest']:
                dp[i]['gym'] = True
            else:
                dp[i]['contest'] = True

    if (dp[i]['contest'] or dp[i]['gym']) == False:
        dp[i]['rest'] = True

count = 0
for i in range(n):
    if dp[i]['rest']:
        count += 1
"""
for i in range(n):
    if dp[i]['contest'] == 1:
        print('c', end=' ')
    if dp[i]['gym'] == 1:
        print('g', end=' ')
    if dp[i]['rest']:
        print('r', end=' ')
print()
"""

print(count)


n = int(input())
numbers = list(map(int, input().split(' ')))

memo = [[0 for _ in range(4)] for _ in range(n)]

first = numbers[0]
if first != 0:
    if first == 3:
        memo[0][1] = 1
        memo[0][2] = 1
    else:
        memo[0][first] = 1

for i in range(1,n):
    j = numbers[i]

    ## Can always choose to do nothing
    memo[i][0] = max(memo[i-1])

    if j == 1 or j == 3:
        memo[i][1] = max(memo[i-1][2], memo[i-1][0]) + 1
    if j == 2 or j == 3:
        memo[i][2] = max(memo[i-1][1], memo[i-1][0]) + 1

print(n-max(memo[n-1]))


n = int(input())
numbers = list(map(int, input().split(' ')))

memo = [[0 for _ in range(4)] for _ in range(n)]

first = numbers[0]
if first != 0:
    if first == 3:
        memo[0][1] = 1
        memo[0][2] = 1
    else:
        memo[0][first] = 1

for i in range(1,n):
    j = numbers[i]
    for k in range(0, i):
        if k == i-1:
            if j == 0 or j == 3:
                memo[i][0] = max(memo[i][0], max(memo[k]))
            if j == 1 or j == 3:
                memo[i][1] = max(memo[i][1], max(memo[k][2], memo[k][0]) + 1)
            if j == 2 or j == 3:
                memo[i][2] = max(memo[i][2], max(memo[k][1], memo[k][0]) + 1)
        else:
            maximum = max(memo[k])
            if j == 0:
                memo[i][0] = maximum
            elif j == 3:
                memo[i][1] = max(memo[i][1], maximum + 1)
                memo[i][2] = max(memo[i][2], maximum + 1)
            else:
                memo[i][j] = max(memo[i][j], maximum + 1)

print(n-max(memo[n-1]))


n=int(input())
l=list(map(int,input().split()))
rest=0
i=0
while i <n:

    if i<=n-3:
        if l[i]==1 and l[i+1]==1:
            i=i+1
            rest=rest+1

        elif l[i]==2 and l[i+1]==2:
            i=i+1
            rest=rest+1

        elif l[i]==1 and l[i+1]==3 and l[i+2]==2:
            i=i+2
            rest=rest+1

        elif l[i]==2 and l[i+1]==3 and l[i+2]==1:
            i=i+2
            rest=rest+1
    if i==n-2:
        if l[i] == 1 and l[i + 1] == 1:
            i = i + 1
            rest = rest + 1

        elif l[i] == 2 and l[i + 1] == 2:
            i = i + 1
            rest = rest + 1

    if l[i]==0:
        rest=rest+1
    i=i+1

print(rest)


n=int(input())
l=list(map(int,input().split()))
rest=0
i=0
while i <n:

    if i<=n-2:
        if l[i]==1 and l[i+1]==1:
            i=i+1
            rest=rest+1

        elif l[i]==2 and l[i+1]==2:
            i=i+1
            rest=rest+1

    if i<=n-3:
        if l[i]==1 and l[i+1]==3 and l[i+2]==2:
            i=i+2
            rest=rest+1

        elif l[i]==2 and l[i+1]==3 and l[i+2]==1:
            i=i+2
            rest=rest+1

    if l[i]==0:
        rest=rest+1
    i=i+1

print(rest)


n=int(input())
l =list(map(int,input().split()))
r=0
x=0
for i in range(len(l)):
 if l[i]==0 or l[i]==x:
  r+=1
  x=0
 elif l[i]==3:
  if(x!=0):
   x=3-x
 else:
  x=l[i]
print(r)


# cook your dish here

n = int(input())
dp = [0, 0, 0]
l = list(map(int,input().split()))
for i in l:
    tmp=dp[:]
    dp[0]= min(tmp)+1
    dp[1]= min(tmp[0], tmp[2]) if i==1 or i==3  else 10e6
    dp[2]= min(tmp[0], tmp[1]) if i==2 or i==3 else 10e6
print(min(dp))


def rev(a) :
	if a == 1 :
		return 2
	return 1

def solve(n,s):
	for i in range(n):
		if(s[i] == 3 and i == 0) :
			k = 0
			for j in range(n) :
				k = j - 1
				if(s[j] != 3) :
					break
			for j in range(k,-1,-1):
				s[j] = rev(s[j+1])
		elif(i != 0) :
			if(s[i] == 3) :
				s[i] = rev(s[i-1])
			elif(s[i] == 0) :
				s[i] = 0
			else :
				if(s[i] == s[i-1]) :
					s[i] = 0
	return s.count(0)

n = int(input())
li = list(map(int,input().split()))
print(solve(n,li))


def rev(a) :
	if a == 1 :
		return 2
	return 1

def solve(n,s):
	prev = 0
	for i in range(n):
		if(s[i] == 3 and prev == 0) :
			k = 0
			for j in range(i,n) :
				k = j - 1
				if(s[j] != 3) :
					break
			for j in range(k,i-1,-1):
				s[j] = rev(s[j+1])
		elif(i != 0) :
			if(s[i] == 3) :
				s[i] = rev(s[i-1])
			elif(s[i] == 0) :
				s[i] = 0
			else :
				if(s[i] == s[i-1]) :
					s[i] = 0
		prev = s[i]
	return s.count(0)

n = int(input())
li = list(map(int,input().split()))
print(solve(n,li))
# print(len(li))


def vacations(n, d, a):
    prev = 3
    res = 0
    for i in a:
        if (i == prev and prev != 3):
            i = 0
        elif (i == 3 and prev != 3):
            i -= prev
        if i == 0:
            res += 1
        prev = i
    return res

n = input()
d = input()
a = list(map(int, d.split(' ')))
print(vacations(n, d, a))


numday = input()
dayorder = input()
array = map(int, dayorder.split(' '))
sumrest = 0
prev = 3

for i in array:
    if (i = prev and prev != 3):
        i = 0
    elif (i == 3 and prev != 3)
        i -= prev
    if i = 0:
        sumrest += 1

    prev = i

print(sumrest)


numday = input()
dayorder = input()
array = map(int, dayorder.split(' '))
sumrest = 0
prev = 3

for i in array:
    if (i == prev and prev != 3):
        i = 0
    elif (i == 3 and prev != 3)
        i -= prev
    if i == 0:
        sumrest += 1

    prev = i

print(sumrest)


numday = input()
dayorder = input()
array = map(int, dayorder.split(' '))
sumrest = 0
prev = 3

for i in array:
    if (i == prev and prev != 3):
        i = 0
    elif (i == 3 and prev != 3):
        i -= prev
    if i == 0:
        sumrest += 1

    prev = i

print(sumrest)


import collections
t = int(input())
l = list(map(int,input().split()))
c = 0
prev = 4
for i in range(len(l)):
     if l[i] == 0:
          c+=1
          prev = 0
          continue
     if l[i] == 3:
          if prev ==4:
               continue
          elif prev == 1:
               prev = 2
          elif prev == 2:
               prev = 1

          continue
     if l[i] == prev:
          c+=1
          prev = 0
          continue
     else:
          prev = l[i]
else:
     print(c)


import collections
t = int(input())
l = list(map(int,input().split()))
c = 0
prev = 4
for i in range(len(l)):
     if l[i] == 0:
          c+=1
          continue
     if l[i] == 3:
          if prev ==4:
               continue
          elif prev == 1:
               prev = 2
          elif prev == 2:
               prev = 1

          continue
     if l[i] == prev:
          c+=1
          continue
     else:
          prev = l[i]
else:
     print(c)


import collections
l = list(map(int,input().split()))
c = 0
prev = 4
for i in range(len(l)):
     if l[i] == 0:
          c+=1
          prev = 0
          continue
     if l[i] == 3:
          if prev ==4:
               continue
          elif prev == 1:
               prev = 2
          elif prev == 2:
               prev = 1

          continue
     if l[i] == prev:
          c+=1
          continue
     else:
          prev = l[i]
else:
     print(c)


import collections
t = int(input())
l = list(map(int,input().split()))
c = 0
prev = 4
for i in range(len(l)):
     if l[i] == 0:
          c+=1
          prev = 0
          continue
     if l[i] == 3:
          if prev ==4:
               continue
          elif prev == 1:
               prev = 2
          elif prev == 2:
               prev = 1

          continue
     if l[i] == prev:
          c+=1
          continue
     else:
          prev = l[i]
else:
     print(c)


n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
	if a[i]==0:
		cnt+=1
for i in range(n-1):
	if (a[i]==1 and a[i+1]==1) or (a[i]==2 and a[i+1]==2):
		cnt+=1
		i+=1
ghabli=0
cnt3=0
for i in range(n):
	if a[i]==3:
		cnt3+=1
	elif a[i]==1 or a[i]==2:
		if ghabli==a[i] and cnt3%2==0 and cnt3!=0:
			cnt+=1
		if ghabli!=a[i] and cnt3%2==1 and cnt3!=0:
			cnt+=1
		cnt3=0
		ghabli=a[i]
	else:
		cnt3=0
		ghabli=0
print(cnt)


n=int(input())
a=list(map(int,input().split()))
cnt=0
x=0
for i in range(n):
	if a[i]!=3:
		x=i
		break
for i in range(x,n):
	if a[i]==0:
		cnt+=1
	if i>0 and a[i]==2 and a[i-1]==2:
		a[i]=0
		cnt+=1
	if i>0 and a[i]==1 and a[i-1]==1:
		a[i]=0
		cnt+=1
	if a[i]==3 and a[i-1]==1:
		a[i]=2
	if a[i]==3 and a[i-1]==2:
		a[i]=1
print(cnt)


n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
	if a[i]==0:
		cnt+=1
for i in range(n-1):
	if (a[i]==1 and a[i+1]==1) or (a[i]==2 and a[i+1]==2):
		cnt+=1
		i+=1
ghabli=0
cnt3=0
for i in range(n):
	if a[i]==3:
		cnt3+=1
	elif a[i]==1 or a[i]==2:
		if ((ghabli==2 and a[i]==2 ) or (ghabli==1 a[i]==1)) and cnt3%2==0 and cnt3!=0:
			cnt+=1
		if ((ghabli==2 and a[i]==1 ) or (ghabli==1 a[i]==2)) and cnt3%2==1 and cnt3!=0:
			cnt+=1
		cnt3=0
		ghabli=a[i]
	else:
		cnt3=0
		ghabli=0
print(cnt)


n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
	if a[i]==0:
		cnt+=1
for i in range(n-1):
	if (a[i]==1 and a[i+1]==1) or (a[i]==2 and a[i+1]==2):
		cnt+=1
		i+=1
ghabli=0
cnt3=0
for i in range(n):
	if a[i]==3:
		cnt3+=1
	elif a[i]==1 or a[i]==2:
		if ghabli==a[i] and cnt3%2==0 and cnt3!=0:
			cnt+=1
		if ghabli!=a[i] and cnt3%2==1 and cnt3!=0:
			cnt+=1
		cnt3=0
		ghabli=a[i]
print(cnt)


n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
	if a[i]==0:
		cnt+=1
for i in range(n-1):
	if (a[i]==1 and a[i+1]==1) or (a[i]==2 and a[i+1]==2):
		cnt+=1
		i+=1
ghabli=0
cnt3=0
for i in range(n):
	if a[i]==3:
		cnt3+=1
	elif a[i]==1 or a[i]==2:
		if ghabli==a[i] and cnt3%2==0 and cnt3!=0:
			cnt+=1
		if ghabli!=a[i] and cnt3%2==1 and cnt3!=0:
			cnt+=1
		cnt3=0
		ghabli=a[i]
	else:
		cnt3=0
print(cnt)


n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
	if a[i]==0:
		cnt+=1
for i in range(n-1):
	if (a[i]==1 and a[i+1]==1) or (a[i]==2 and a[i+1]==2):
		cnt+=1
		i+=1
ghabli=0
cnt3=0
for i in range(n):
	if a[i]==3:
		cnt3+=1
	elif a[i]==1 or a[i]==2:
		if ((ghabli==2 and a[i]==2 ) or (ghabli==1 and a[i]==1)) and cnt3%2==0 and cnt3!=0:
			cnt+=1
		if ((ghabli==2 and a[i]==1 ) or (ghabli==1 and a[i]==2)) and cnt3%2==1 and cnt3!=0:
			cnt+=1
		cnt3=0
		ghabli=a[i]
	else:
		cnt3=0
		ghabli=0
print(cnt)


n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
	if a[i]==0:
		cnt+=1
for i in range(n-1):
	if (a[i]==1 and a[i+1]==1) or (a[i]==2 and a[i+1]==2):
		cnt+=1
		i+=1
ghabli=0
cnt3=0
for i in range(n):
	if a[i]==3:
		cnt3+=1
	elif a[i]==1 or a[i]==2:
		if ((ghabli==2 and a[i]==2 ) or (ghabli==1 and a[i]==1)) and cnt3%2==0 and cnt3!=0 and i<n-1 and a[i]!=a[i+1]:
			cnt+=1
		if ((ghabli==2 and a[i]==1 ) or (ghabli==1 and a[i]==2)) and cnt3%2==1 and cnt3!=0 and i<n-1 and a[i]!=a[i+1]:
			cnt+=1
		cnt3=0
		ghabli=a[i]
	else:
		cnt3=0
		ghabli=0
print(cnt)


n = int(input())
#n, m = map(int, input().split())
#s = input()
c = list(map(int, input().split()))
l = 0
if c[0] == 3:
    c[0] = 0
elif c[0] == 0:
    l += 1
for i in range(1, n):
    if c[i - 1] == c[i]:
        l += 1
        c[i] = 0
    elif c[i] == 3:
        if c[i - 1] == 0:
            c[i] = 0
        else:
            c[i] = 3 - c[i - 1]
    elif c[i] == 0:
        l += 1
print(l)


n = int(input())
#n, m = map(int, input().split())
#s = input()
c = list(map(int, input().split()))
l = 0
if c[0] == 3:
    c[0] = 0
for i in range(1, n):
    if c[i - 1] == c[i]:
        l += 1
        c[i] = 0
    elif c[i] == 3:
        if c[i - 1] == 0:
            c[i] = 0
        else:
            c[i] = 3 - c[i - 1]
    elif c[i] == 0:
        l += 1


n = int(input())
#n, m = map(int, input().split())
#s = input()
c = list(map(int, input().split()))
l = 0
if c[0] == 3:
    c[0] = 0
for i in range(1, n):
    if c[i - 1] == c[i]:
        l += 1
        c[i] = 0
    elif c[i] == 3:
        if c[i - 1] == 0:
            c[i] = 0
        else:
            c[i] = 3 - c[i - 1]
    elif c[i] == 0:
        l += 1
print(l)


n = int(input())
#n, m = map(int, input().split())
#s = input()
c = list(map(int, input().split()))
l = 0
if c[0] == 3:
    c[0] = 0
if c[0] == 0:
    l += 1
for i in range(1, n):
    if c[i - 1] == c[i]:
        l += 1
        c[i] = 0
    elif c[i] == 3:
        if c[i - 1] == 0:
            c[i] = 0
        else:
            c[i] = 3 - c[i - 1]
    elif c[i] == 0:
        l += 1
print(l)


n = int(input())
arr = list(map(int, input().split()))
res, prev = 0, 0
for x in arr:
	if x == prev or x == 0:
		prev = 0
		res += 1
	elif x == 1 or x == 2:
		prev = x
	elif prev > 0 and x == 3:
		prev = 3 - prev
print(res)


n=int(input())
a=list(map(int,input().split()))
ans,cnt=0,0
last=0
for i in a:
    if i==0:
        ans+=1
        last=i
    elif i==1 or i==2:
        if cnt==0:
            if last==i:
                ans+=1
        else:
            if cnt%2==1 and last!=i and last!=0:
                ans+=1
            if cnt%2==0 and last==i:
                ans+=1
            cnt=0
        last=i
    else:
        cnt+=1
    #print(i,ans)
print(ans)


n=int(input())
a=list(map(int,input().split()))
ans,cnt=0,0
last=0
for i in a:
    if i==0:
        ans+=1
        last=i
    elif i==1 or i==2:
        if cnt==0:
            if last==i:
                ans+=1
                last=0
            else:
                last=i
        else:
            if cnt%2==1 and last!=i and last!=0:
                ans+=1
            if cnt%2==0 and last==i:
                ans+=1
            cnt=0
            last=i
    else:
        cnt+=1
    #print(i,ans,last)
print(ans)


user = int(input())
n = list(input().split(" "))
l = len(n)-1
if int(n[0]) == 3 and int(n[l])!=3:
	n.reverse()
r = 0
a = 0
c = 0
res = []
for i in n:
	if int(i) == 0:
		r = r + 1
		a = 0
		c = c + 1
	if int(i) == 1 :
		if a == 0 or a!=2:
			a = 2
			c = c + 1
		else:
			r = r + 1
			a = 0
			c = c + 1
	if int(i) == 2:
		if a == 0 or a!=1:
			a = 1
			c = c + 1
		else:
			r = r + 1
			a = 0
			c = c + 1
	if int(i) == 3:
		if a==0:
			while c < len(n) and n[c] == 3:
				c = c + 1
			if c < len(n):
				if n[c] == 1:
					a = 2
				elif n[c] == 2:
					a = 1
		elif a!=1:
			a = 1
		elif a!=2:
			a = 2
print(r)


# Name : Sachdev Hitesh
# College : GLSICA
user = int(input())
n = list(input().split(" "))
r = 0
a = 0
for i in n:
	if int(i) == 0:
		r = r + 1
		a = 0
	if int(i) == 1 :
		if a == 0 or a!=2:
			a = 2
		else:
			r = r + 1
			a = 0
	if int(i) == 2:
		if a == 0 or a!=1:
			a = 1
		else:
			r = r + 1
			a = 0
	if int(i) == 3:
		if a == 0 or a!=1:
			a = 1
		elif a == 0 or a!=2:
			a = 2
print(r)