#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[1000005], vis[1000005];
bitset<1000005> dp;
vector<int> v;
vector<pair<int, int> > vec;
void solve_v() {
  sort(v.begin(), v.end());
  int now = -1;
  for (int i = 0; i < (int)v.size(); ++i) {
    if (now == -1 || v[i] != vec[now].first)
      vec.push_back(make_pair(v[i], 1)), ++now;
    else
      ++vec[now].second;
  }
}
void do_more(int cnt, int val) {
  int x = 1, y = val;
  while (x <= cnt) {
    dp = dp | (dp << y);
    cnt -= x;
    x <<= 1, y <<= 1;
  }
  y = cnt * val;
  if (y) dp = dp | (dp << y);
}
void gao_mi() {
  dp.reset(), dp.set(0);
  for (int i = 0; i < (int)vec.size(); ++i)
    do_more(vec[i].second, vec[i].first);
  printf("%d ", dp[k] == 0 ? k + 1 : k);
}
void gao_ma() {
  int x = 0, y = 0;
  for (int i = 0; i < (int)v.size(); ++i) {
    x += v[i] / 2;
    if (v[i] & 1) ++y;
  }
  int ans = min(k, x) * 2;
  if (k > x) ans += min(y, k - x);
  printf("%d\n", ans);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      int now = i, cnt = 0;
      while (!vis[now]) ++cnt, vis[now] = 1, now = a[now];
      v.push_back(cnt);
    }
  solve_v();
  gao_mi();
  gao_ma();
  return 0;
}
