#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 200005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void file_put() {
  freopen("filename.in", "r", stdin);
  freopen("filename.out", "w", stdout);
}
int n, m, a[N], b[N], s = 0, l, r, mid, ans, ret, cnt[N], L, R, t = 0;
bool check(int k) {
  ret = t, memset(cnt, 0, sizeof(cnt)), L = 1, R = 0;
  while (R < k)
    ++R, ret += (cnt[a[R]] + 1 >= b[a[R]]) - (cnt[a[R]] >= b[a[R]]),
        cnt[a[R]]++;
  if (ret >= m) return 1;
  while (R < n) {
    ++R, ret += (cnt[a[R]] + 1 >= b[a[R]]) - (cnt[a[R]] >= b[a[R]]),
        cnt[a[R]]++;
    ret += (cnt[a[L]] - 1 >= b[a[L]]) - (cnt[a[L]] >= b[a[L]]), cnt[a[L]]--,
        ++L;
    if (ret >= m) return 1;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
  for (int i = (1); i <= (m); ++i) scanf("%d", &b[i]), s += b[i], t += (!b[i]);
  l = 1, r = n, ans = s - 1;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ans - s);
  return 0;
}
