#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>


using namespace std;
//using namespace atcoder;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 998244353;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//union-find木について
//サイズによる更新をしている
ll par[201010];
ll rank2[201010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 1;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
		rank2[y] += rank2[x];
	}
	else {
		par[y] = x;
		rank2[x] += rank2[y];
	}
}


ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll dp[110][110];
vector<vector<pair<ll, ll>>>to;
bool flag[101010];
ll dist[101010];

void dfs(ll v) {
	flag[v] = true;
	for (auto nv : to[v]) {
		ll nv2 = nv.first;
		ll dist2 = nv.second;
		if (flag[nv2] == false) {
			dist[nv2] = dist[v] + dist2;
			dfs(nv2);
		}
	}
}

ll c[1010][1010];
ll a[1010], b[1010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	init(n);
	rep(i, n) {
		ll x;
		cin >> x;
		x--;
		unite(i, x);
	}
	map<ll, ll>mp;
	rep(i, n) {
		mp[find(i)]++;
	}
	ll res = 0;
	for (auto p : mp) {
		res++;
	}
	ll ans = 0;
	COMinit();
	for (ll i = 1;i <= res;++i) {
		ans += COM(res, i);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define Int register int
#define Swap(a, b) a ^= b, b ^= a, a ^= b
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define Max(x, y) ((x) < (y) ? (y) : (x))
#define Min(x, y) ((x) < (y) ? (x) : (y))
#define Isdigit(ch) (ch >= '0' and ch <= '9')

const LL MOD = 1e9 + 7;
typedef pair <int, int> T;
const int MAXN = 1e3 + 10, MAXM = 1e6 + 10, INF = 1e9;

inline LL Read () {
	LL f = 0, x = 0;
	char ch = getchar ();
	
	while (!isdigit (ch) ) {
		f |= (ch == '-'), ch = getchar ();
	}
	
	while (isdigit (ch) ) {
		x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar ();
	}
	
	return f ? -x : x;
}

inline void Write (const LL &x) {
	if (x < 0 ) {
		putchar ('-'), Write (-x);
		return ;
	}
	
	if (x > 9 ) {
		Write (x / 10);
	}
	
	putchar ((x % 10) ^ 48);
	return ;
}

LL t, n, m;

inline LL Qkpow (LL Base, LL x) {
	LL Total = 1;
	
	while (x ) {
		if (x & 1 ) {
			Total = Total * Base % MOD;
		}
		
		x >>= 1, Base = Base * Base % MOD;
	}
	
	return Total;
}

inline LL C(LL n, LL m) {
	n = Min (n, m - n);
	LL Answer = 1;
	
	for (LL i = 1; i <= n; ++ i ) {
		Answer = Answer * Qkpow (i, MOD - 2) % MOD;
	}
	
	for (LL i = m; i ^ (m - n); -- i ) {
		Answer = Answer * i % MOD;
	}
	
	return Answer;
}

signed main () {
	t = n = Read (), m = Read () + n;
	
	for (LL i = 1; i <= t; ++ i ) {
		n += Read ();
	}
	
	if (m < n ) {
		Write (0), putchar ('\n');
		return 0;
	}
	
	Write (C (n, m)), putchar ('\n');
	return 0;
}
  