#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, p[N], k, cnt[N], t2[N];
bitset<N> dp;
vector<int> A;
bool mark[N];
void PREP() {
  int x, t;
  for (int i = 1; i <= n; i++) {
    if (mark[i]) continue;
    x = i, t = 0;
    while (!mark[x]) mark[x] = 1, t++, x = p[x];
    cnt[t]++;
  }
  x = 1;
  while (x <= n) t2[x] = x, x *= 2;
  for (int i = 1; i <= n; i++) {
    if (t2[i])
      x = i;
    else
      t2[i] = x;
  }
  for (int i = 1; i <= n; i++) {
    x = 1, t = t2[cnt[i]];
    if (cnt[i]) {
      A.push_back(x * i);
      while (x < t) A.push_back(x * i), x *= 2;
      if (cnt[i] - t > 0) A.push_back(i * (cnt[i] - t2[cnt[i]]));
    }
  }
}
void MIN(int k) {
  dp[0] = 1;
  for (auto x : A) dp = (dp << x) | dp;
  if (!dp[k]) k++;
  printf("%d ", k);
  return;
}
void MAX(int k) {
  int res = 0;
  for (int i = n; i; --i) {
    int q = cnt[i];
    while (k && q--) {
      if (k - i / 2 < 0)
        res += 2 * k, k = 0;
      else
        res += i / 2 * 2, k -= i / 2;
    }
  }
  for (int i = n; i; --i) {
    int q = cnt[i];
    while (i & 1 && k && q--) k--, res++;
  }
  printf("%d ", res);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  PREP();
  MIN(k);
  MAX(k);
}
