#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int Max_N(25050);
const int Max_K(405);
const int MOD(1000000000 + 7);

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

constexpr int Mult(int a, int b)
{
	return a * 1LL * b % MOD;
}

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

constexpr int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

void exgcd(int a, int b, int &x, int &y)
{
	if (b == 0)
		x = 1, y = 0;
	else
		exgcd(b, a % b, y, x), y -= x * (a / b);
}

inline int inverse(int a)
{
	int invx, invy;
	exgcd(a, MOD, invx, invy);
	return (invx % MOD + MOD) % MOD;
}

inline void upd(int &a, int b)
{
	a = Add(a, b);
}

int N, K, M, A[Max_N], Last[Max_K], powerK[Max_N], Ans, Fac[Max_N], Inv[Max_N];

bool check()
{
	for (int i = 1, j = 1;i <= M;++i)
	{
		j = max(j, Last[A[i]] + 1), Last[A[i]] = i;
		if (i - j + 1 == K)
			return true;
	}
	return false;
}

int F[Max_N][Max_K];
void dp()
{
	for (int k = 1;k <= K - 1;++k)
		F[0][k] = 1;
	for (int n = 1;n <= N;++n)
		for (int k = 1, Sum = 0;k <= K - 1;++k)
			upd(Sum, F[n - 1][k]), F[n][k] = Add(Sum, k + 1 < K ? Mult(F[n - 1][k + 1], K - k) : 0);
}

int G[Max_N][Max_K], H[Max_N][Max_K];
void dp2()
{
	G[1][1] = K, H[1][1] = K * (1 >= M);
	for (int n = 2;n <= N;++n)
		for (int k = K - 1, SumG = 0, SumH = 0;k >= 1;--k)
		{
			upd(SumG, G[n - 1][k]);
			G[n][k] = Add(SumG, k - 1 ? Mult(G[n - 1][k - 1], K - (k - 1)) : 0);
			upd(SumH, H[n - 1][k]);
			H[n][k] = Add(SumH, k - 1 ? Mult(H[n - 1][k - 1], K - (k - 1)) : 0);
			if (k >= M)
				upd(H[n][k], Add(SumG, k - 1 ? Mult(G[n - 1][k - 1], K - (k - 1)) : 0));
		}
}

int main()
{
	gi(N), gi(K), gi(M);
	if (K > N)
	{
		printf("0");
		return 0;
	}
	Fac[0] = 1;
	for (int i = 1;i <= N;++i)
		Fac[i] = Mult(Fac[i - 1], i);
	Inv[N] = inverse(Fac[N]);
	for (int i = N - 1;i >= 0;--i)
		Inv[i] = Mult(Inv[i + 1], i + 1);
	for (int i = 1;i <= M;++i)
		gi(A[i]);
	powerK[0] = 1;
	for (int i = 1;i <= N;++i)
		powerK[i] = Mult(powerK[i - 1], K);
	if (check())
		Ans = 0;
	else
	{
		memset(Last, 0, sizeof(Last));
		int x, y;
		for (x = 1;x <= M;++x)
		{
			if (Last[A[x]])
				break;
			Last[A[x]] = 1;
		}
		--x;
		memset(Last, 0, sizeof(Last));
		for (y = M;y >= 1;--y)
		{
			if (Last[A[y]])
				break;
			Last[A[y]] = 1;
		}
		++y, y = M - y + 1;
		if (x == M && y == M)
		{
			dp2();
			for (int k = 1;k <= K - 1;++k)
				upd(Ans, H[N][k]);
			Ans = Mult(Ans, inverse(Mult(Fac[K], Inv[K - M])));
		}
		else
		{
			dp();
			for (int n = 0;n <= N - M;++n)
				upd(Ans, Mult(F[n][x], F[N - M - n][y]));
		}
	}
	print(Sub(Mult(powerK[N - M], N - M + 1), Ans));
	return 0;
}

Measured memory_bytes: 84224