Problem: We are given a permutation sequence a1, a2, ..., an of numbers from 1 to n. Let's assume that in one second, we can choose some disjoint pairs (u1, v1), (u2, v2), ..., (uk, vk) and swap all aui and avi for every i at the same time (1 ≤ ui < vi ≤ n). The pairs are disjoint if every ui and vj are different from each other.

We want to sort the sequence completely in increasing order as fast as possible. Given the initial permutation, calculate the number of ways to achieve this. Two ways are different if and only if there is a time t, such that the set of pairs used for swapping at that time are different as sets (so ordering of pairs doesn't matter). If the given permutation is already sorted, it takes no time to sort, so the number of ways to sort it is 1.

To make the problem more interesting, we have k holes inside the permutation. So exactly k numbers of a1, a2, ..., an are not yet determined. For every possibility of filling the holes, calculate the number of ways, and print the total sum of these values modulo 1000000007 (109 + 7).

Input

The first line contains two integers n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 12). The second line contains the permutation sequence a1, ..., an (0 ≤ ai ≤ n). If a number is not yet determined, it is denoted as 0. There are exactly k zeroes. All the numbers ai that aren't equal to zero are distinct.

Output

Print the total sum of the number of ways modulo 1000000007 (109 + 7).

Examples

Input

5 0
1 5 2 4 3


Output

6


Input

5 2
1 0 2 4 0


Output

7

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, k, nxt[110001], pre[110001], len[22], cnt, ans, now, nw,
    mod = 1000000007;
int num[110000], maybe[1000000], pos[110000], cnt_may, pa[12], dp[2][1 << 12],
    g[1 << 12][13], st[1 << 12], cnt_st;
int ff[1 << 12], dig[12], num_d, fac[110000], fc[1 << 12], flag, fl[1 << 12],
    cn[100000], cnt_cn, iden[100000], size[1 << 12];
bool is[110000];
struct pp {
  int st, id;
};
pp not_z[1000000];
int cnt_z;
vector<int> f[100011], adj[110000];
bool vis[110000];
int tt(int id) {
  if (pa[id] == id) return id;
  pa[id] = tt(pa[id]);
  return pa[id];
}
int power(int a, int n) {
  int res;
  if (n == 0) return 1;
  res = power(a, n / 2);
  res = (int)((long long)res * (long long)res % mod);
  if (n % 2) res = (int)((long long)res * (long long)a % mod);
  return res;
}
void dfs(int id) {
  int i, j, s, p, q, ip, npa[12];
  bool have[12] = {0};
  if (id >= k) {
    nw = 1;
    bool ca = flag;
    for (i = 0; i < cnt_cn; i++) {
      ip = cn[i];
      if (num[ip] > 0) {
        nw = (int)((long long)nw * (long long)f[ip][num[ip]] % mod);
        if (ip >= 3) ca = true;
        if (nw == 0) return;
      }
    }
    if (ca) {
      for (i = 0; i < k; i++) {
        if (tt(i) == i) {
          if (nw > 0 && size[i] - 1 >= 2)
            nw = (int)((long long)nw * (long long)fac[size[i] - 1] % mod);
        }
      }
      now = (now + nw) % mod;
    }
    return;
  }
  for (i = 0; i < k; i++) npa[i] = pa[i];
  for (i = 0; i <= id; i++) {
    for (j = 0; j < k; j++) pa[j] = npa[j];
    ip = tt(i);
    if (!have[ip]) {
      if (ip != id) pa[id] = ip;
      have[ip] = true;
      if (id != ip) {
        num[len[id]]--;
        if (num[len[id]] == 0) {
          int i1 = pos[len[id]], i2 = cnt_cn - 1;
          swap(cn[i1], cn[i2]);
          pos[cn[i1]] = i1;
          pos[cn[i2]] = -1;
          cnt_cn--;
        }
        num[len[ip]]--;
        if (num[len[ip]] == 0) {
          int i1 = pos[len[ip]], i2 = cnt_cn - 1;
          swap(cn[i1], cn[i2]);
          pos[cn[i1]] = i1;
          pos[cn[i2]] = -1;
          cnt_cn--;
        }
        len[ip] += len[id];
        size[ip] += size[id];
        num[len[ip]]++;
        if (pos[len[ip]] < 0) {
          pos[len[ip]] = cnt_cn;
          cn[cnt_cn++] = len[ip];
        }
      }
      dfs(id + 1);
      if (id != ip) {
        size[ip] -= size[id];
        num[len[ip]]--;
        if (num[len[ip]] == 0) {
          int i1 = pos[len[ip]], i2 = cnt_cn - 1;
          swap(cn[i1], cn[i2]);
          pos[cn[i1]] = i1;
          pos[cn[i2]] = -1;
          cnt_cn--;
        }
        len[ip] -= len[id];
        num[len[ip]]++;
        if (pos[len[ip]] < 0) {
          pos[len[ip]] = cnt_cn;
          cn[cnt_cn++] = len[ip];
        }
        num[len[id]]++;
        if (pos[len[id]] < 0) {
          pos[len[id]] = cnt_cn;
          cn[cnt_cn++] = len[id];
        }
      }
      have[ip] = true;
    }
  }
}
int main() {
  int i, j, s, p, q, id, siz, nst, ip;
  scanf("%d%d", &n, &k);
  for (i = 0; i <= n; i++) {
    f[i].clear();
    adj[i].clear();
    if (i == 0)
      fac[0] = 1;
    else
      fac[i] = (int)((long long)fac[i - 1] * (long long)i % mod);
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= n / i; j++) f[i].push_back(0);
    f[i][0] = 1;
    f[i][1] = i;
    for (j = 2; j <= n / i; j++) {
      now = (int)((long long)i * (long long)f[i][j - 1] % mod);
      f[i][j] = (f[i][j] + now) % mod;
      now = (int)((long long)i * (long long)f[i][j - 2] % mod);
      now = (int)((long long)now * (long long)(j - 1) % mod);
      f[i][j] = (f[i][j] + now) % mod;
    }
  }
  memset(pre, 0, sizeof(pre));
  for (i = 1; i <= n; i++) {
    scanf("%d", &nxt[i]);
    if (nxt[i] > 0) pre[nxt[i]] = i;
  }
  cnt = 0;
  memset(vis, false, sizeof(vis));
  memset(num, 0, sizeof(num));
  cnt_may = flag = 0;
  ans = 1;
  memset(pos, -1, sizeof(pos));
  for (i = 1; i <= n; i++) {
    if (pre[i] > 0) continue;
    j = i;
    len[cnt] = 0;
    while (true) {
      len[cnt]++;
      vis[j] = true;
      j = nxt[j];
      if (j == i || j == 0) break;
    }
    num[len[cnt]]++;
    cnt++;
  }
  flag = 0;
  for (i = 1; i <= n; i++) {
    if (vis[i]) continue;
    j = i;
    len[cnt] = 0;
    while (true) {
      len[cnt]++;
      vis[j] = true;
      j = nxt[j];
      if (j == i) break;
    }
    if (len[cnt] >= 3) flag = 1;
    num[len[cnt]]++;
    if (len[cnt] >= 3) flag = 1;
  }
  memset(is, false, sizeof(is));
  cnt_may = 0;
  for (i = 0; i < (1 << k); i++) {
    now = 0;
    for (j = 0; j < k; j++) {
      if (i & (1 << j)) now += len[j];
    }
    is[now] = true;
    maybe[cnt_may++] = now;
  }
  ans = 1;
  memset(pos, -1, sizeof(pos));
  cnt_cn = 0;
  for (i = 1; i <= n; i++) {
    if (!is[i] && num[i]) {
      ans = (int)((long long)ans * (long long)f[i][num[i]] % mod);
      num[i] = 0;
    } else if (num[i] > 0) {
      pos[i] = cnt_cn;
      cn[cnt_cn++] = i;
    }
  }
  for (i = 0; i < cnt; i++) {
    pa[i] = i;
    size[i] = 1;
  }
  now = 0;
  dfs(0);
  ans = (int)((long long)ans * (long long)now % mod);
  if (flag == 0) {
    for (i = 1; i < (1 << k); i++) {
      now = 0;
      cnt = 0;
      for (j = 0; j < k; j++) {
        if (i & (1 << j)) {
          now += len[j];
          cnt++;
        }
      }
      if (now <= 2)
        fl[i] = 0;
      else
        fl[i] = 1;
    }
    if (now <= 2)
      fl[i] = 0;
    else
      fl[i] = 1;
    now = 0;
    memset(dp[0], 0, sizeof(dp[0]));
    dp[0][0] = 1;
    for (i = 1; i < (1 << k); i++) {
      for (s = 0; !(i & (1 << s)); s++)
        ;
      j = i;
      while (j > 0) {
        if (fl[j] == 0 && (j & (1 << s)))
          dp[0][i] = (dp[0][i] + dp[0][i - j]) % mod;
        j = ((j - 1) & i);
      }
    }
    ans = (ans + dp[0][(1 << k) - 1]) % mod;
  }
  printf("%d\n", ans);
  return 0;
}