#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	VI a(n);
	_rep(i, 0, n) cin >> a[i];
	VI b(a.begin(), a.begin() + m);
	sort(all(b));
	if(b[0] != 0) {
		cout << 0 << endl;
		return 0;
	}
	int ans = b.back() + 1;	
	unordered_map<int,int> mp;
	mp[b[0]] ++;
	bool ok = false;
	_rep(i, 1, m) {
		mp[b[i]] ++;
		if(ok) continue;
		if(b[i] > b[i - 1] + 1) {
			ans = b[i - 1] + 1;
			ok = true;
		} 
	}
	_rep(i, 0, n - m){
		mp[a[i]] -- ;
		mp[a[i + m]] ++;
		if(a[i] < ans){
			if(mp[a[i]] == 0) ans = a[i];
		}	
	}
	cout << ans << endl;
	return 0;
} 
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline


#include <bits/stdc++.h>

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n;
    std::string s;

    std::cin >> n >> s;

    int ans = 0;

    for (int i = 0; i < n; i++) {
        int at = 0, gc = 0;

        for (int j = i; j < n; j++) {
            if (s[j] == 'A') ++at;
            else if (s[j] == 'T') --at;
            else if (s[j] == 'G') ++gc;
            else --gc;
            
            ans += !(at || gc);
        }
    }

    std::cout << ans;

    return 0;
}

