#include <bits/stdc++.h>
const double pi = 4.0 * atan(1.0);
const double e = exp(1.0);
using namespace std;
int a[200200];
int b[200200];
int c[200200];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  int sum = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    sum += b[i];
  }
  int l = sum;
  int r = n;
  int ans = -1;
  while (l <= r) {
    int q = sum;
    int is = 0;
    int mid = (l + r) >> 1;
    memset(c, 0, sizeof(c));
    for (int i = 1; i <= mid; i++) {
      if (c[a[i]] < b[a[i]]) {
        q--;
      }
      c[a[i]]++;
      if (q == 0) {
        is = 1;
        break;
      }
    }
    for (int i = 2; i <= n - mid + 1; i++) {
      c[a[i - 1]]--;
      if (c[a[i - 1]] < b[a[i - 1]]) {
        q++;
      }
      if (c[a[i + mid - 1]] < b[a[i + mid - 1]]) {
        q--;
      }
      c[a[i + mid - 1]]++;
      if (q == 0) {
        is = 1;
        break;
      }
    }
    if (is == 1) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  if (ans == -1) {
    cout << -1 << endl;
  } else {
    cout << ans - sum << endl;
  }
}
