N, M = map(int, input().split()) S = list(map(int, input().split())) A = list(range(N)) SET = set() for s in S: s -= 1 SET.add((min(A[s], A[s+1]), max(A[s], A[s+1]))) A[s], A[s+1] = A[s+1], A[s] print(len(SET))