#include <bits/stdc++.h>
using namespace std;
bool convert(vector<int> tet, int k) {
  while (tet.size() > 1) {
    int same = 1;
    int X = tet.back();
    while (same < tet.size() &&
           tet[tet.size() - same - 1] == tet[tet.size() - 1])
      same++;
    if (same < k) {
      break;
    }
    for (int e = 0; e < same; e++) tet.pop_back();
    for (int e = 0; e < same / k; e++) tet.push_back(X + 1);
  }
  return (tet.size() == 1);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    vector<int> tet;
    for (int j = i; j < n; j++) {
      if (!tet.size()) {
        ans++;
        tet.push_back(v[j]);
      } else {
        bool good = true;
        while (tet.back() < v[j]) {
          int same = 1;
          int X = tet.back();
          while (same < tet.size() &&
                 tet[tet.size() - same - 1] == tet[tet.size() - 1])
            same++;
          if (same < k) {
            good = false;
            break;
          }
          for (int e = 0; e < same; e++) tet.pop_back();
          for (int e = 0; e < same / k; e++) tet.push_back(X + 1);
        }
        if (!good) break;
        tet.push_back(v[j]);
        if (convert(tet, k)) {
          ans++;
        }
      }
    }
  }
  cout << ans;
}
