def cmb(n, r, mod):#コンビネーションの高速計算  if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 998244353 #出力の制限 N = 2*10**5 g1 = [1]*(N+1) # 元テーブル g2 = [1]*(N+1) #逆元テーブル inverse = [1]*(N+1) #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 N,M = map(int,input().split()) P = list(map(int,input().split())) P = [P[i]-1 for i in range(N)] cycle = [] used = [False]*N for i in range(N): if not used[i]: used[i] = True c = 1 pos = i while not used[P[pos]]: pos = P[pos] used[pos] = True c += 1 cycle.append(c) n = len(cycle) res = 0 for k in range(2,M+1): dp = [[0,0] for i in range(N+1)] dp[0][0] = 1 for i in range(1,N+1): dp[i][0] += dp[i-1][1] dp[i][1] += dp[i-1][0] * max(0,k-1) + dp[i-1][1] * max(0,k-2) dp[i][0] %= mod dp[i][1] %= mod tmp = 1 for l in cycle: tmp *= dp[l][0] * k tmp %= mod if (M-k)%2: res -= cmb(M,k,mod) * tmp else: res += cmb(M,k,mod) * tmp res %= mod print(res*g2[M] % mod)