lG-P2267
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 500000 + 10;
int n, p, m;
int a[N], b[N];
int last[N];
int f[N], s[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> p;
for (int i = 1; i <= n; i ++ ) cin >> a[i], b[i] = a[i];
sort(b + 1, b + 1 + n);
int m = unique(b + 1, b + 1 + n) - (b + 1);
for (int i = 1; i <= n; i ++ ) a[i] = lower_bound(b + 1, b + 1 + m, a[i]) - b;
for (int i = 1; i <= n; i ++ )
{
if (last[a[i]]) f[i] = (s[i - 1] - s[last[a[i]] - 1] + p) % p;
else f[i] = (s[i - 1] + 1) % p;
s[i] = (s[i - 1] + f[i]) % p;
last[a[i]] = i;
}
cout << (s[n] % p + p) % p;
}