#include <bits/stdc++.h>
using namespace std;
char BUF[3500000];
inline void I(int& a) { scanf("%d", &a); }
inline void I(int& a, int& b) { scanf("%d%d", &a, &b); }
inline void I(int& a, int& b, int& c) { scanf("%d%d%d", &a, &b, &c); }
inline void I(int& a, int& b, int& c, int& d) {
  scanf("%d%d%d%d", &a, &b, &c, &d);
}
inline void L(long long& a) { scanf("%lld", &a); }
inline void L(long long& a, long long& b) { scanf("%lld%lld", &a, &b); }
inline void L(long long& a, long long& b, long long& c) {
  scanf("%lld%lld%lld", &a, &b, &c);
}
inline void L(long long& a, long long& b, long long& c, long long& d) {
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
}
inline void S(string& str) {
  str.clear();
  scanf("%s", BUF);
  int s = strlen(BUF);
  for (int i = 0; i < s; i++) str.push_back(BUF[i]);
}
inline void SV(vector<int>& v) {
  v.clear();
  scanf("%s", BUF);
  int s = strlen(BUF);
  for (int i = 0; i < s; i++)
    if ('a' <= BUF[i] && BUF[i] <= 'z')
      v.push_back(BUF[i] - 'a');
    else
      v.push_back(BUF[i] - 'A');
}
const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
int n, k;
int p[1000000];
vector<int> v;
bool saw[1000000];
bitset<1000001> dp;
int cnt[1000001];
int w[1000001];
void solve1() {
  int kk = min(k, n - k);
  for (int i = 0; i < v.size(); i++) cnt[v[i]]++;
  dp[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    if (cnt[i] < 50) {
      for (int j = 0; j < cnt[i]; j++) dp |= (dp << i);
      continue;
    }
    memset(w, -1, sizeof(w));
    bitset<1000001> tmp;
    for (int j = 0; j < kk + 1; j++) {
      if (dp[j]) w[j] = cnt[i];
      if (w[j] >= 0) tmp[j] = 1;
      w[j + i] = w[j] - 1;
    }
    dp = tmp;
  }
  if (dp[kk])
    cout << k;
  else
    cout << k + 1;
}
void solve2() {
  int cnt = 0;
  int kk = k;
  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    if (kk > v[i] / 2) {
      kk -= v[i] / 2;
      ans += (v[i] / 2) * 2;
      v[i] &= 1;
    } else {
      ans += kk * 2;
      cout << ans << endl;
      return;
    }
  }
  for (int i = 0; i < v.size(); i++) {
    if (kk == 0) break;
    if (v[i]) {
      kk--;
      ans += v[i];
    }
  }
  cout << ans << endl;
}
int main() {
  I(n, k);
  for (int i = 0; i < n; i++) I(p[i]);
  for (int i = 0; i < n; i++) p[i]--;
  for (int i = 0; i < n; i++) {
    if (saw[i]) continue;
    int cnt = 1;
    int j = i;
    saw[i] = true;
    while (!saw[p[j]]) {
      saw[p[j]] = true;
      j = p[j];
      cnt++;
    }
    v.push_back(cnt);
  }
  solve1();
  cout << " ";
  solve2();
}
