// editor1
#include <stdio.h>

int main() {
    int N, M;
    scanf("%d", &N);  // Size of hash table
    scanf("%d", &M);  // Number of keys to insert

    int keys[M];
    for (int i = 0; i < M; i++) {
        scanf("%d", &keys[i]);
    }

    // Initialize hash table with -1 (empty slot)
    int hashTable[N];
    for (int i = 0; i < N; i++) {
        hashTable[i] = -1;
    }

    // Insert keys using linear probing
    for (int i = 0; i < M; i++) {
        int key = keys[i];
        int idx = key % N;

        // Linear probing if collision
        while (hashTable[idx] != -1) {
            idx = (idx + 1) % N;
        }
        hashTable[idx] = key;
    }

    // Count clusters
    int clusters = 0;
    for (int i = 0; i < N; i++) {
        if (hashTable[i] != -1) {
            // If current is filled and previous is empty → new cluster
            if (i == 0) {
                if (hashTable[N - 1] == -1) {
                    clusters++;
                }
            } else {
                if (hashTable[i - 1] == -1) {
                    clusters++;
                }
            }
        }
    }

    printf("%d\n", clusters);
return 0;
}
