#include <bits/stdc++.h>
using namespace std;
int t;
int n, k;
int a[2007];
int f[2007][2007];
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    memset(f, 0, sizeof(f));
    int ans = INT32_MAX;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= i; ++j) {
        if (j == a[i])
          f[i][j] = max(f[i - 1][j - 1] + 1, f[i - 1][j]);
        else
          f[i][j] = max(f[i - 1][j - 1], f[i - 1][j]);
        if (f[i][j] >= k) ans = min(ans, i - j);
      }
    }
    cout << (ans == INT32_MAX ? -1 : ans) << endl;
  }
}
