#include <bits/stdc++.h>   using namespace std;   int n, s, a[200100], cnt[200100], ans, kol;   set<int> st;   int main() {     cin >> n >> s;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       if (i == s) {         if (a[i] != 0) {           a[i] = 0;           ans++;         }         st.insert(a[i]);         continue;       }       if (a[i] == 0) {         a[i] = n;         kol++;       }       cnt[a[i]]++;       st.insert(a[i]);     }     for (int i = 1; i <= n; ++i) {       if (i > *st.rbegin()) break;       if (cnt[i] == 0) {         int pp = *st.rbegin();         if (cnt[pp] == 1) {           st.erase(pp);         }         ans++;         st.insert(i);         cnt[pp]--;       }     }     cout << max(ans, kol);   }   