#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
int n, m;
multiset<int> S, S1;
int a[1111111];
int chk[1111111];
bool can(int sum, int n) {
  if (sum < 0 || sum > n) return 0;
  if (sum == 0 || sum == n) return 1;
  S1 = S;
  while (sum && !S1.empty()) {
    multiset<int>::iterator it = S1.lower_bound(sum);
    if (it != S1.end()) {
      if (*it == sum) return 1;
    }
    if (it != S1.begin()) {
      it--;
      sum -= *it;
      S1.erase(it);
    } else {
      return 0;
    }
  }
  return 0;
}
vector<int> V;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int tot = 0, cnt = 0;
  for (int i = 1; i <= n; i++)
    if (!chk[i]) {
      int len = 0;
      for (int j = i; !chk[j]; len++, chk[j] = 1, j = a[j])
        ;
      tot += len / 2;
      if (len % 2 == 1) cnt++;
      S.insert(len);
      V.push_back(len);
    }
  sort((V).begin(), (V).end());
  int ma = 0, mn = n;
  if (tot >= m) {
    ma = 2 * m;
  } else if (m <= tot + cnt) {
    ma = m + tot;
  } else {
    ma = n;
  }
  int flg = (can(m, n) || can(n - m, n));
  for (int times = 0; times < 5; times++) {
    int x = rand() % V.size();
    multiset<int>::iterator it = S.lower_bound(V[x]);
    S.erase(it);
    if (can(m - V[x], n - V[x]) || can(n - m, n - V[x])) {
      flg = 1;
      break;
    }
    S.insert(V[x]);
  }
  if (flg) {
    printf("%d %d\n", m, ma);
  } else {
    printf("%d %d\n", min(n, m + 1), ma);
  }
  return 0;
}
