#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
const int inf1 = 1e9;
const long long int inf2 = 1e18;
const int N = 100000;
using namespace std;
int dirs[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int solve() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  map<int, int> mp;
  int cnt = 0;
  int j = 0;
  for (int i = 0; i < m; i++) {
    while (j < n && b[i] > mp[i + 1]) {
      mp[a[j]]++;
      j++;
    }
    if (j == n && b[i] > mp[i + 1]) {
      cout << -1 << "\n";
      return 0;
    }
  }
  for (auto i : mp) {
    cnt += (i.second - b[i.first - 1]);
  }
  int ans = cnt;
  for (int i = 1; i < n; i++) {
    mp[a[i - 1]]--;
    if (mp[a[i - 1]] >= b[a[i - 1] - 1]) {
      cnt--;
      ans = max(0, min(ans, cnt));
      continue;
    }
    cnt--;
    int f = 1;
    while (j < n && f) {
      if (a[j] == a[i - 1]) f = 0;
      mp[a[j]]++;
      j++;
      cnt++;
    }
    if (j == n && f) {
      cout << ans << "\n";
      return 0;
    }
    ans = max(0, min(ans, cnt));
  }
  cout << ans << "\n";
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
