import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int N, M; scanf("%d %d\n", &N, &M);
    int[] a = new int[M];
    foreach (i; 0 .. M) { scanf("%d\n", &a[i]); }
    auto G = new bool[][](M, M);
    foreach (i; 0 .. M) {
        foreach (j; i + 1 .. M) {
            if (abs(a[i] - a[j]) <= 1) {
                G[i][j] = true;
            }
        }
    }
    int Ans = 0;
    int dfs(int x) {
        int ret = 0;
        foreach (i; 0 .. M) {
            if (G[x][i]) {
                ret = max(ret, dfs(i));
            }
        }
        return ret + 1;
    }
    version(Debug) {
        foreach (i; 0 .. M) {
            writef("%3d: ", a[i]);
            foreach (j; 0 .. M) {
                if (G[i][j]) {
                    writef("%3d", a[j]);
                }
            }
            writeln;
        }
    }
    foreach (int i; 0 .. M) {
        Ans = max(Ans, dfs(i));
    }
    writeln(Ans);
}