#include <bits/stdc++.h>
using namespace std;
#define MX 1000000000
int n,m;
vector <int> a;
vector <int> Need;
int Sum=0;

bool Check(int mid){

    vector <int> Count=Need;//ApsoluteDifferences
    vector <int> NonAbs=Need;
    unsigned long long Difference=Sum;
for(int i=0;i<mid+Sum;i++){
        int PrevCount=Count [a[i]-1];
Count [a[i]-1]--;
NonAbs[a[i]-1]--;
if(Count[a[i]-1]<=0)Count[a[i]-1]=0;
Difference-=PrevCount;
Difference+=Count[a[i]-1];

}

if(Difference==0)return 1;
for(int i=Sum+mid;i<n;i++){//cout<<"CAAL!"<<endl;
 int PrevCount=Count [a[i]-1];

Count [a[i]-1]=max(Count [a[i]-1]-1,0);
NonAbs[a[i]-1]--;

Difference-=PrevCount;
Difference+=Count[a[i]-1];

NonAbs[a[i-Sum-mid]-1]++;

if(NonAbs[a[i-Sum-mid]-1]>0){
    Count[a[i-Sum-mid]-1]++;
    Difference++;
}

if(Difference==0)return 1;
//cout <<Difference<<endl;
}
return 0;
}
void End(int x){
cout <<x<<endl;
exit(0);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >>n>>m;
a.resize(n);
Need.resize(m);
for(int i=0;i<n;i++){
    cin >>a[i];
}

for(int i=0;i<m;i++){
    cin >>Need[i];
    Sum+=Need[i];
}

int low=1;
int hi=n-Sum-1;
if(!Check(hi+1))End(-1);
if(Check(0))End(0);
int rez=hi+1;
//cout <<"111111111111111111111111"<<endl;
//Check(1);
//cout <<"BINNNNN"<<endl;
while(low<hi){
int mid=(hi+low)/2;

if(Check(mid)){hi=mid-1;rez=min(rez,mid);}
else low=mid;

}

if(Check(low))End(low);
if(Check(hi))End(hi);
if(!Check(rez))cout <<-1<<endl;
else
cout <<rez<<endl;
}


//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll>
#define ull unsigned ll
#define vll vector<ll>
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
cin>>m;
vll v(n);
read(v);
ll count[m+1]={0};
ll need[m+1];
ll needsum=0;
for(int i=1;i<=m;i++)
{cin>>need[i];needsum+=need[i];}
int l=0;
int r=0;
int sum=needsum;
ll ans=llmax;
for(;l<n;l++)
{
   while(r<n && sum>0)
   {
       count[v[r]]++;
       if(count[v[r]]<=need[v[r]])
       sum--;
       r++;
   }
   //deb(l,r,sum);
   if(sum==0)
   {
     ans=min(ans,(r-l)-needsum);
   }
   count[v[l]]--;
   if(count[v[l]]<need[v[l]])
   sum++;
}
if(ans==llmax)
{
  cout<<-1;
}
else
cout<<ans;
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}


//Dragon_warrior7(IITK)
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll>
#define ull unsigned ll
#define vll vector<ll>
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
cin>>m;
vll v(n);
read(v);
ll count[m+1]={0};
ll need[m+1];
ll needsum=0;
for(int i=1;i<=m;i++)
{cin>>need[i];needsum+=need[i];}
int l=0;
int r=0;
int sum=needsum;
ll ans=llmax;
for(;l<n;l++)
{
   while(r<n && sum>0)
   {
       count[v[r]]++;
       if(count[v[r]]<=need[v[r]])
       sum--;
       r++;
   }
   //deb(l,r,sum);
   if(sum==0)
   {
     ans=min(ans,(r-l)-needsum);
   }
   count[v[l]]--;
   if(count[v[l]]<need[v[l]])
   sum++;
}
if(ans==llmax)
{
  cout<<-1;
}
else
cout<<ans;
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("O3")
//#pragma GCC optimize ("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define _ inline
#define f first
#define sec second
#define pb push_back
#define ins insert
#define ers erase
#define mk make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define int ll
#define forn(i, n) for (register int i(1); i <= n; i++)
#define fore(i, n) for (register int i(0); i < n; i++)
#define endl "\n"

#define right rightt
#define left leftt
#define next nextt
#define prev prevv

mt19937 Random(int(time(0)));

const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int P = 239017;
const long long BINF = 1e18 + 10;
const ld EPS = 1e-9;

const int N = 2e5 + 10;
vector<int> arr[N];
int c[N], need[N], cur_cnt[N];
_ void source() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        int color;
        cin >> color;
        arr[color].pb(i);
        c[i] = color;
    }
    int len = 0, mn, r = 0;
    for (int i = 1; i <= m; i++) {
        int cnt;
        cin >> cnt;
        need[i] = cnt;
        len += cnt;
        if (arr[i].size() < cnt) {
            cout << -1;
            exit(0);
        }
        r = max(r, arr[i][cnt - 1]);
    }
    mn = r;
    for (int i = 1; i <= r; i++) {
        cur_cnt[c[i]]++;
    }
    for (int i = 2; i <= n; i++) {
        cur_cnt[c[i - 1]]--;
        while (r < n && cur_cnt[c[i - 1]] < need[c[i - 1]]) {
            r++;
            cur_cnt[c[r]]++;
        }
        if (cur_cnt[c[i - 1]] >= need[c[i - 1]]) {
            mn = min(mn, r - i + 1);
        }
        else {
            break;
        }
    }
    cout << mn - len;
}

signed main() {
#ifdef EXTRATERRESTRIAL_
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin);
    //freopen(TASK".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    source();
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("O3")
//#pragma GCC optimize ("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define _ inline
#define f first
#define sec second
#define pb push_back
#define ins insert
#define ers erase
#define mk make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define int ll
#define forn(i, n) for (register int i(1); i <= n; i++)
#define fore(i, n) for (register int i(0); i < n; i++)
#define endl "\n"

#define right rightt
#define left leftt
#define next nextt
#define prev prevv

mt19937 Random(int(time(0)));

const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int P = 239017;
const long long BINF = 1e18 + 10;
const ld EPS = 1e-9;

const int N = 2e5 + 10;
vector<int> arr[N];
int c[N], need[N], cur_cnt[N];
_ void source() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        int color;
        cin >> color;
        arr[color].pb(i);
        c[i] = color;
    }
    int len = 0, mn = INF, r = 0;
    for (int i = 1; i <= m; i++) {
        int cnt;
        cin >> cnt;
        need[i] = cnt;
        len += cnt;
        if (arr[i].size() < cnt) {
            cout << -1;
            exit(0);
        }
    }
    for (int i = 1; i <= m; i++) {
        while (r < n && cur_cnt[i] < need[i]) {
            r++;
            cur_cnt[c[r]]++;
        }
        if (cur_cnt[i] < need[i]) {
            cout << -1;
            exit(0);
        }
    }
    mn = r;
    for (int i = 2; i <= n; i++) {
        cur_cnt[c[i - 1]]--;
        while (r < n && cur_cnt[c[i - 1]] < need[c[i - 1]]) {
            r++;
            cur_cnt[c[r]]++;
        }
        if (cur_cnt[c[i - 1]] >= need[c[i - 1]]) {
            mn = min(mn, r - i + 1);
        }
        else {
            break;
        }
    }
    cout << mn - len;
}

signed main() {
#ifdef EXTRATERRESTRIAL_
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin);
    //freopen(TASK".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    source();
    return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
//#define mp make_pair
#define pb push_back
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define plii pair<LL,pii>
#define pii pair<int, int>
#define piii pair<pii, pii>
#define pdi pair<double, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 2e5 + 5;
int a[N], k[N], cnt[N], n, m, tot = 0;
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), cnt[a[i]]++;
    for (int i = 1; i <= m; ++i) scanf("%d", &k[i]), tot += k[i];
    for (int i = 1; i <= m; ++i) if(cnt[i] < k[i]) return 0*puts("-1");
    int l = 1, r = n;
    for (int i = n; i >= 1; --i) {
        r = i;
        if(cnt[a[i]]-1 < k[a[i]]) break;
        cnt[a[i]]--;
    }
    int ans = n;
    for (int i = r; i <= n; ++i) {
        while(cnt[a[l]]-1 >= k[a[l]]) cnt[a[l]]--, ++l;
        ans = min(ans, i-l+1-tot);
        cnt[a[i+1]]++;
    }
    printf("%d\n", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
ull MOD=212370440130137957ll;
int mod=1e9+7;
ll INF=1e18;
const int maxn=1e6+10;
const int maxl=3e3+10;
const double PI=acos(-1.0);
const double eps=1e-8;
mt19937_64 rng((ull)(new char));
int m,n;
int a[maxn],k[maxn];
int l,r;
int cnt[maxn];
int s;
int ans=1e9;
bool ch()
{
	_for(co,1,m+1)if(cnt[co]<k[co])return 0;return 1;
}
void findfir()
{
	l=1;r=0;
	for(int co=1;co<=m;++co)
	{
		while(r<n&&cnt[co]<k[co])++cnt[a[++r]];
	}
	if(1)
	{
		if(!ch())cout<<"-1",exit(0);
		ans=min(ans,r-s);
	}
	for(++l;l<=n;++l)
	{
		int la=l-1;
		--cnt[a[la]];
		while(r<l)++cnt[a[++r]];
		while(r<n&&cnt[a[la]]<k[a[la]])++cnt[a[++r]];
		if(r>=n)
		{
			if(cnt[a[la]]<k[a[la]])cout<<ans,exit(0);
			else ans=min(ans,n-l+1-s);
		}
		else ans=min(ans,r-l+1-s);
	}
	cout<<ans;exit(0);
}
int main()
{
	fast;cin>>n>>m;_for(t,1,n+1)cin>>a[t];_for(i,1,m+1)cin>>k[i],s+=k[i];
	findfir();
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
ull MOD=212370440130137957ll;
int mod=1e9+7;
ll INF=1e18;
const int maxn=1e6+10;
const int maxl=3e3+10;
const double PI=acos(-1.0);
const double eps=1e-8;
mt19937_64 rng((ull)(new char));
int m,n;
int a[maxn],k[maxn];
int l,r;
int cnt[maxn];
int s;
int ans=1e9;
bool ch()
{
	_for(co,1,m+1)if(cnt[co]<k[co])return 0;return 1;
}
void findfir()
{
	l=1;r=0;
	for(int co=1;co<=m;++co)
	{
		while(r<n&&cnt[co]<k[co])++cnt[a[++r]];
	}
	if(1)
	{
		if(!ch())cout<<"-1",exit(0);
		ans=min(ans,n-s);
	}
	for(++l;l<=n;++l)
	{
		int la=l-1;
		--cnt[a[la]];
		while(r<l)++cnt[a[++r]];
		while(r<n&&cnt[a[la]]<k[a[la]])++cnt[a[++r]];
		if(r>=n)
		{
			if(cnt[a[la]]<k[a[la]])cout<<ans,exit(0);
			else ans=min(ans,n-l+1-s);
		}
		else ans=min(ans,r-l+1-s);
	}
	cout<<ans;exit(0);
}
int main()
{
	fast;cin>>n>>m;_for(t,1,n+1)cin>>a[t];_for(i,1,m+1)cin>>k[i],s+=k[i];
	findfir();
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 200009;
ll n,i,m,s,lo,hg,g,mid,ans;
ll a[N],k[N],f[N];
bool can(ll p)
{
    rep(i,0,N) f[i] = 0;
    ll satis = g;
    for(i = 1;i <= p;i++){
        f[a[i]] += 1;
        if(f[a[i]] == k[a[i]])
            satis += 1;
    }
    if(satis == m) return 1;
    for(i = 1;i + p <= n;i++){

        if(f[a[i]] == k[a[i]])
            satis -= 1;
        f[a[i]] -= 1;

        f[a[i + p]] += 1;
        if(f[a[i + p]] == k[a[i + p]])
            satis += 1;

        if(satis == m)
            return 1;
    }
    return 0;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,1,n + 1) cin>>a[i];
    rep(i,1,m + 1){
        cin>>k[i];
        s += k[i];
        g += (k[i] == 0);
    }
    lo = 1; hg = n; ans = -1;
    while(lo <= hg){
        mid = (lo + hg) / 2;
        if(can(mid)){
            ans = mid;
            hg = mid - 1;
        }
        else
            lo = mid + 1;
    }
    cout<<(ans == -1 ? -1 : ans - s);
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 200009;
ll n,i,m,s,lo,hg,mid,ans;
ll a[N],k[N],f[N];
bool can(ll p)
{
    rep(i,0,N) f[i] = 0;
    ll satis = 0;
    for(i = 1;i <= p;i++){
        f[a[i]] += 1;
        if(f[a[i]] == k[a[i]])
            satis += 1;
    }
    if(satis == m) return 1;
    for(i = 1;i + p <= n;i++){
        f[a[i]] -= 1;
        if(f[a[i]] + 1 == k[a[i]])
            satis -= 1;

        f[a[i + p]] += 1;
        if(f[a[i + p]] == k[a[i + p]])
            satis += 1;

        if(satis == m)
            return 1;
    }
    return 0;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,1,n + 1) cin>>a[i];
    rep(i,1,m + 1) cin>>k[i],s += k[i];
    lo = s; hg = n; ans = -1;
    while(lo <= hg){
        mid = (lo + hg) / 2;
        if(can(mid)){
            ans = mid;
            hg = mid - 1;
        }
        else
            lo = mid + 1;
    }
    cout<<(ans == -1 ? -1 : ans - s);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define MOD 998244353
#define INF 1000000000000000000
#define endll "\n"
#define pb push_back
#define forn(i,n) for(i=0;i<n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll N = 1e6 + 5;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n, m, i, j;
	cin >> n >> m;
	ll a[n], b[m + 1];
	for (i = 0; i < n; i++)
		cin >> a[i];
	ll sum = 0;
	for (i = 1; i <= m; i++)
		cin >> b[i], sum += b[i];
	map<ll, ll> mp, pos;
	for (i = 0; i < n; i++)
	{
		if (mp[a[i]] < b[a[i]])
			mp[a[i]]++, pos[a[i]] = i;
	}
	for (i = 1; i <= m; i++)
	{
		if (mp[i] < b[i])
		{
			cout << -1;
			return 0;
		}
	}
	ll maxi = 0;
	for (auto j : pos)
		maxi = max(maxi, j.ss);
	map<ll, ll> mp1;
	for (i = 0; i <= maxi; i++)
	{
		mp1[a[i]]++;
	}
	ll ans = (maxi + 1 - sum);
	j = 0;
	while (mp1[a[j]] > b[a[j]])
	{
		mp1[a[j]]--;
		j++;
	}
	ans = min(ans, maxi - j + 1 - sum);
	for (i = maxi + 1; i < n; i++)
	{
		mp1[a[i]]++;
		while (mp1[a[j]] > b[a[j]])
		{
			mp1[a[j]]--;
			j++;
		}
		ans = min(ans, i - j + 1 - sum);
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define MOD 998244353
#define INF 1000000000000000000
#define endll "\n"
#define pb push_back
#define forn(i,n) for(i=0;i<n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll N = 1e6 + 5;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n, m, i, j;
	cin >> n >> m;
	ll a[n], b[m + 1];
	for (i = 0; i < n; i++)
		cin >> a[i];
	ll sum = 0;
	for (i = 1; i <= m; i++)
		cin >> b[i], sum += b[i];
	map<ll, ll> mp, pos;
	for (i = 0; i < n; i++)
	{
		if (mp[a[i]] < b[a[i]])
			mp[a[i]]++, pos[a[i]] = i;
	}
	for (i = 1; i <= m; i++)
	{
		if (mp[i] < b[i])
		{
			cout << -1;
			return 0;
		}
	}
	ll maxi = 0;
	for (auto j : pos)
		maxi = max(maxi, j.ss);
	map<ll, ll> mp1;
	for (i = 0; i <= maxi; i++)
	{
		mp1[a[i]]++;
	}
	ll ans = (maxi + 1 - sum);
	j = 0;
	for (i = maxi + 1; i < n; i++)
	{
		mp1[a[i]]++;
		while (mp1[a[j]] > b[a[j]])
		{
			mp1[a[j]]--;
			j++;
		}
		ans = min(ans, i - j + 1 - sum);
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr[1000000], coun[1000000];
int main(){
int n, m, mini=2e9, s=0, s1=0;
cin>>n>>m;
for(int i=1; i<=n; i++)
    cin>>arr[i];
for(int i=1; i<=m; i++)
    cin>>coun[i], s1+=coun[i], s+=coun[i]>0;
int r=0;
for(int i=1; i<=n; i++){
    while(s>0 && r<n){
        s1--;
        r++;
        if(coun[arr[r]]==1)
            s--;
        coun[arr[r]]--;
    }
    if(s==0)
        mini=min(mini, -s1);
    if(coun[arr[i]]==0)
        s++;
    coun[arr[i]]++;
    s1++;
}
if(mini==2000000000)
    cout<<-1;
else
    cout<<mini;
return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define pb push_back
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forrn(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))
#define all(v) v.begin(), v.end()
#define mp make_pair
#define ff first
#define ss second

const int mod = 1e9 + 7;
const int INF = 1791791791;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // Code here:

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    forn(i, n) {
        cin >> a[i];
        a[i]--;
    }
    int sk = 0;
    vector<int> k(m);
    forn(i, m) {
        cin >> k[i];
        sk += k[i];
    }

    vector<queue<int> > q(m);
    multiset<int> s;
    forn(_, m)
        s.insert(INF);

    int mn = INF;
    for (int i = n - 1; i >= 0; i--) {
        q[a[i]].push(i);
        if ((int)q[a[i]].size() == k[a[i]]) {
            s.erase(s.find(INF));
            s.insert(q[a[i]].front());
        }
        if ((int)q[a[i]].size() > k[a[i]]) {
            s.erase(s.find(q[a[i]].front()));
            q[a[i]].pop();
            s.insert(q[a[i]].front());
        }
        mn = min(mn, (*prev(s.end()) - i + 1) - sk);
    }

    if (mn > n)
        cout << -1 << endl;
    else
        cout << mn << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define pb push_back
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forrn(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))
#define all(v) v.begin(), v.end()
#define mp make_pair
#define ff first
#define ss second

const int mod = 1e9 + 7;
const int INF = 1791791791;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // Code here:

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    forn(i, n) {
        cin >> a[i];
        a[i]--;
    }
    int sk = 0, nz = 0;
    vector<int> k(m);
    forn(i, m) {
        cin >> k[i];
        sk += k[i];
        nz += (k[i] > 0);
    }

    vector<queue<int> > q(m);
    multiset<int> s;
    forn(_, nz)
        s.insert(INF);

    int mn = INF;
    for (int i = n - 1; i >= 0; i--) {
        if (k[a[i]] > 0) {
            q[a[i]].push(i);
            if ((int)q[a[i]].size() == k[a[i]]) {
                s.erase(s.find(INF));
                s.insert(q[a[i]].front());
            }
            if ((int)q[a[i]].size() > k[a[i]]) {
                s.erase(s.find(q[a[i]].front()));
                q[a[i]].pop();
                s.insert(q[a[i]].front());
            }
        }
        mn = min(mn, (*prev(s.end()) - i + 1) - sk);
    }

    if (mn > n)
        cout << -1 << endl;
    else
        cout << mn << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e6+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,m,u[N],cnt[N],k[N],r,ans=MOD,need,c;

void add(ll t){
	if(cnt[t]>=k[t])need++,cnt[t]++;
	else cnt[t]++,c+=(cnt[t]==k[t]?1:0);
}

void sub(ll t){
	if(cnt[t]>k[t]){
		need--,cnt[t]--;
	}else c--,cnt[t]--;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	REP1(i,n)cin>>u[i];REP1(i,m)cin>>k[i];
	REP1(i,m)if(k[i]==0)c++;
	REP1(i,n){
		while(c!=m&&r<n)add(u[++r]);
		if(c!=m)continue;
		ans=min(ans,need);
		sub(u[i]);
	}
	cout<<(ans==MOD?-1:ans)<<"\n";
	return 0;
}


#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5 + 10;

int n, m, a[MAXN], cnt[MAXN], needCnt[MAXN];
int satisfied, carry;

void add(int x) {
	cnt[x]++;
	if(cnt[x] == needCnt[x]) satisfied++;
	else if(cnt[x] > needCnt[x]) carry++;
}

void kick(int x) {
	if(cnt[x] > needCnt[x]) carry--;
	if(cnt[x] == needCnt[x]) satisfied--;
	cnt[x]--;
}

int32_t main() {
#ifdef Fekete
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("debuger.txt", "w", stderr);
#else

#endif // Fekete

    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", &needCnt[i]);
    }
    int ans = 12345678;
    for(int i = 1, j = 1; i <= n; i++) {
    	while(j <= n && satisfied != m) {
			add(a[j]);
			j++;
		}
    	if(satisfied == m) {
    		ans = min(ans, carry);
    	}
    	kick(a[i]);
    }
    if(ans == 12345678) ans = -1;
    cout << ans;
}


#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5 + 10;

int n, m, a[MAXN], cnt[MAXN], needCnt[MAXN];
int satisfied, carry;

void add(int x) {
	cnt[x]++;
	if(cnt[x] == needCnt[x]) satisfied++;
	else if(cnt[x] > needCnt[x]) carry++;
}

void kick(int x) {
	if(cnt[x] > needCnt[x]) carry--;
	if(cnt[x] == needCnt[x]) satisfied--;
	cnt[x]--;
}

int32_t main() {
#ifdef Fekete
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("debuger.txt", "w", stderr);
#else

#endif // Fekete

    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", &needCnt[i]);
    	if(needCnt[i] == 0) satisfied++;
    }
    int ans = 12345678;
    for(int i = 1, j = 1; i <= n; i++) {
    	while(j <= n && satisfied != m) {
			add(a[j]);
			j++;
		}
    	if(satisfied == m) {
    		ans = min(ans, carry);
    	}
    	kick(a[i]);
    	if(i == j) j++;
    }
    if(ans == 12345678) ans = -1;
    cout << ans;
}


#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5 + 10;

int n, m, a[MAXN], cnt[MAXN], needCnt[MAXN];
int satisfied, carry;

void add(int x) {
	cnt[x]++;
	if(cnt[x] == needCnt[x]) satisfied++;
	else if(cnt[x] > needCnt[x]) carry++;
}

void kick(int x) {
	if(cnt[x] > needCnt[x]) carry--;
	if(cnt[x] == needCnt[x]) satisfied--;
	cnt[x]--;
}

int32_t main() {
#ifdef Fekete
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("debuger.txt", "w", stderr);
#else

#endif // Fekete

    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", &needCnt[i]);
    }
    int ans = 12345678;
    for(int i = 1, j = 1; i <= n; i++) {
    	while(j <= n && satisfied != m) {
			add(a[j]);
			j++;
		}
    	if(satisfied == m) {
    		ans = min(ans, carry);
    	}
    	kick(a[i]);
    	if(i == j) j++;
    }
    if(ans == 12345678) ans = -1;
    cout << ans;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define mp                          make_pair
#define pb							push_back
#define sz(x)                       int(x.size())
#define all(x)                      x.begin(),x.end()
#define lson                        rt<<1,l,m
#define rson                        rt<<1|1,m+1,r
#define rep(i,s,e)                  for (int i=s;i<=e;i++)
#define rev(i,s,e)                  for (int i=s;i>=e;i--)

typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int n,m,num,cnt,ans=INF;
LL a[MAXN], b[MAXN], c[MAXN];
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,m) scanf("%d",&b[i]), num+=b[i];
	int l = 1, r = 1;
	for (;r<=n;r++)
	{
		c[ a[r] ]++;
		if (c[ a[r] ] == b[ a[r] ])
		{
			cnt++;
			if (cnt == m) break;
		}
	}
	if (r==n+1) return 0*puts("-1");
	while (c[ a[l] ] > b[ a[l] ])
	{
		c[ a[l] ] --;
		l++;
	}
	ans = min(ans, r-l+1-num);

	for (r++;r<=n;r++)
	{
		c[ a[r] ]++;
		if (a[r] == a[l])
		{
			while (c[ a[l] ] > b[ a[l] ])
			{
				c[ a[l] ] --;
				l++;
			}
			ans = min(ans, r-l+1-num);
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define mp                          make_pair
#define pb							push_back
#define sz(x)                       int(x.size())
#define all(x)                      x.begin(),x.end()
#define lson                        rt<<1,l,m
#define rson                        rt<<1|1,m+1,r
#define rep(i,s,e)                  for (int i=s;i<=e;i++)
#define rev(i,s,e)                  for (int i=s;i>=e;i--)

typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int n,m,num,cnt,ans=INF;
int a[MAXN], b[MAXN], c[MAXN];
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,m) scanf("%d",&b[i]), num+= b[i];
	int l = 1, r = 1;
	for (;r<=n;r++)
		if (++c[ a[r] ] == b[ a[r] ])
		{
			cnt++;
			if (cnt == m) break;
		}

	while (c[ a[l] ] > b[ a[l] ])
	{
		c[ a[l] ] --;
		l++;
	}
	ans = min(ans, r-l+1-num);
	for (r++;r<=n;r++)
	{
		c[ a[r] ]++;
		while (c[ a[l] ] > b[ a[l] ])
		{
			c[ a[l] ] --;
			l++;
		}
		ans = min(ans, r-l+1-num);
	}
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define mp                          make_pair
#define pb							push_back
#define sz(x)                       int(x.size())
#define all(x)                      x.begin(),x.end()
#define lson                        rt<<1,l,m
#define rson                        rt<<1|1,m+1,r
#define rep(i,s,e)                  for (int i=s;i<=e;i++)
#define rev(i,s,e)                  for (int i=s;i>=e;i--)

typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int n,m,num,cnt,ans=INF;
int a[MAXN], b[MAXN], c[MAXN];
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,m) scanf("%d",&b[i]), num+= b[i];
	int l = 1, r = 1;
	for (;r<=n;r++)
		if (++c[ a[r] ] == b[ a[r] ])
		{
			cnt++;
			if (cnt == m) break;
		}
	if (r==n+1) return 0*puts("-1");
	while (c[ a[l] ] > b[ a[l] ])
	{
		c[ a[l] ] --;
		l++;
	}
	ans = min(ans, r-l+1-num);
	for (r++;r<=n;r++)
	{
		c[ a[r] ]++;
		while (c[ a[l] ] > b[ a[l] ])
		{
			c[ a[l] ] --;
			l++;
		}
		ans = min(ans, r-l+1-num);
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define mp                          make_pair
#define pb							push_back
#define sz(x)                       int(x.size())
#define all(x)                      x.begin(),x.end()
#define lson                        rt<<1,l,m
#define rson                        rt<<1|1,m+1,r
#define rep(i,s,e)                  for (int i=s;i<=e;i++)
#define rev(i,s,e)                  for (int i=s;i>=e;i--)

typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int n,m,num,cnt,ans=INF;
int a[MAXN], b[MAXN], c[MAXN];
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,m)
	{
		scanf("%d",&b[i]);
		if (b[i] == 0) cnt++;
		num+= b[i];
	}
	int l = 1, r = 1;
	for (;r<=n;r++)
	{
		c[ a[r] ]++;
		if (c[ a[r] ] == b[ a[r] ])
		{
			cnt++;
			if (cnt == m) break;
		}
	}
	if (r==n+1) return 0*puts("-1");
	while (c[ a[l] ] > b[ a[l] ])
	{
		c[ a[l] ] --;
		l++;
	}
	ans = min(ans, r-l+1-num);
	for (r++;r<=n;r++)
	{
		c[ a[r] ]++;
		if (a[r] == a[l])
		{
			while (c[ a[l] ] > b[ a[l] ])
			{
				c[ a[l] ] --;
				l++;
			}
			ans = min(ans, r-l+1-num);
		}
	}
	printf("%d\n",max(ans,0));
	return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define mp                          make_pair
#define pb							push_back
#define sz(x)                       int(x.size())
#define all(x)                      x.begin(),x.end()
#define lson                        rt<<1,l,m
#define rson                        rt<<1|1,m+1,r
#define rep(i,s,e)                  for (int i=s;i<=e;i++)
#define rev(i,s,e)                  for (int i=s;i>=e;i--)

typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int n,m,num,cnt,ans=INF;
int a[MAXN], b[MAXN], c[MAXN];
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,m) scanf("%d",&b[i]), num+= b[i];
	int l = 1, r = 1;
	for (;r<=n;r++)
	{
		c[ a[r] ]++;
		if (c[ a[r] ] == b[ a[r] ])
		{
			cnt++;
			if (cnt == m) break;
		}
	}
	if (r==n+1) return 0*puts("-1");
	while (c[ a[l] ] > b[ a[l] ])
	{
		c[ a[l] ] --;
		l++;
	}
	ans = min(ans, r-l+1-num);
	for (r++;r<=n;r++)
	{
		c[ a[r] ]++;
		if (a[r] == a[l])
		{
			while (c[ a[l] ] > b[ a[l] ])
			{
				c[ a[l] ] --;
				l++;
			}
			ans = min(ans, r-l+1-num);
		}
	}
	printf("%d\n",max(ans,0));
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
using namespace std;

int n,m,hi,lo, res = 1e9;
int cnt[200005];
int a[200005], b[200005], matched;

int total;

int main(){

	cin >> n >> m;
	for (int i=0;i<n;i++) cin >> a[i];
	for (int i=1;i<=m;i++) {
		cin >> b[i], total+=b[i];
		if(b[i] == 0)
			matched++;
	}

	for(int i = 0, j = 0; i < n; i++){
		while(j < n && matched < m){
			if(++cnt[a[j]] == b[a[j]])
				matched++;
			j++;
		}

		if(j == n && matched < m) break;

		int usingSabers = j-i;
		res = min(res, usingSabers-total);

		if(cnt[a[i]]-- == b[a[i]])
			matched--;
	}

	cout << (res == 1e9? -1: res) << endl;
}

/*

()()()()()

*/


#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector< int> a(n);
    for (int &e : a) {
        cin >> e;
        e--;
    }

    vector< int> b(m);
    for (int &e : b) cin >> e;
    int L = accumulate(begin(b), end(b), 0);

    vector< int> c(m);
    int C = 0;
    int res = -1;

    for (int i = 0, j = 0; i < n; i++) {

        while (j < n && C < m) {
            int x = a[j];
            c[x]++;
            if (c[x] == b[x]) C++;
            j++;
        }

        if (C == m) {
            if (res == -1) res = j - i - L;
            res = min(res, j - i - L);
        }

        int x = a[i];
        c[x]--;
        if (c[x] == b[x] - 1) C--;
    }

    cout << res << endl;
}


#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector< int> a(n);
    for (int &e : a) {
        cin >> e;
        e--;
    }

    vector< int> b(m);
    for (int &e : b) cin >> e;
    int L = accumulate(begin(b), end(b), 0);

    vector< int> c(m);
    int C = 0;
    int res = -1;

    for (int i = 0; i < m; i++) if (c[i] == b[i]) C++;

    for (int i = 0, j = 0; i < n; i++) {

        while (j < n && C < m) {
            int x = a[j];
            c[x]++;
            if (c[x] == b[x]) C++;
            j++;
        }

        if (C == m) {
            if (res == -1) res = j - i - L;
            res = min(res, j - i - L);
        }

        int x = a[i];
        c[x]--;
        if (c[x] == b[x] - 1) C--;
    }

    cout << res << endl;
}


#include<bits/stdc++.h>
using namespace std;

int arr[200010];
int res[200010];
vector<int> vec[200010];
int cur[200010];

int main()
{
    int n, m, i, j, k;
    int sum = 0;
    scanf("%d%d", &n, &m);
    for(i=1;i<=n;i++)
    {
        scanf("%d", &arr[i]);
        vec[arr[i]].push_back(i);
    }
    for(i=1;i<=m;i++)
    {
        scanf("%d", &res[i]);
        sum += res[i];
    }

    set<int> ss;

    int ans = n;

    for(i=1;i<=m;i++)
    {
        if(vec[i].size() < res[i])
        {
            printf("-1\n");
            return 0;
        }

        cur[i] = res[i] - 1;
        ss.insert(vec[i][cur[i]]);
    }

    ans = min(ans, *prev(ss.end()) - sum);

    for(i=2;i<=n;i++)
    {
        int t = arr[i - 1];
        if(cur[t] + 1 == vec[t].size())
            break;

        ss.erase(vec[t][cur[t]]);
        cur[t]++;
        ss.insert(vec[t][cur[t]]);

        ans = min(ans, *prev(ss.end()) - sum - i + 1);
    }
    printf("%d\n", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int arr[200010];
int res[200010];
vector<int> vec[200010];
int cur[200010];

int main()
{
    int n, m, i, j, k;
    int sum = 0;
    scanf("%d%d", &n, &m);
    for(i=1;i<=n;i++)
    {
        scanf("%d", &arr[i]);
        vec[arr[i]].push_back(i);
    }
    for(i=1;i<=m;i++)
    {
        scanf("%d", &res[i]);
        sum += res[i];
    }

    set<int> ss;

    int ans = n;

    for(i=1;i<=m;i++)
    {
        if(res[i] == 0)
            continue;

        if(vec[i].size() < res[i])
        {
            printf("-1\n");
            return 0;
        }

        cur[i] = res[i] - 1;
        ss.insert(vec[i][cur[i]]);
    }

    ans = min(ans, *prev(ss.end()) - sum);

    for(i=2;i<=n;i++)
    {
        int t = arr[i - 1];

        if(res[t] != 0)
        {
            if(cur[t] + 1 == vec[t].size())
                break;

            ss.erase(vec[t][cur[t]]);
            cur[t]++;
            ss.insert(vec[t][cur[t]]);
        }

        ans = min(ans, *prev(ss.end()) - sum - i + 1);
    }
    printf("%d\n", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define     pb              push_back
#define     popb            pop_back
#define     ll              long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     check           printf("check")
#define     sqr(x)          (x)*(x)
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     Pair            pair<ll,ll>
#define     MAX             1000000000000014
#define     MIN             -100000000000014
#define     Fread           freopen("input.txt","r",stdin);
#define     Fwrite          freopen("output.txt","w",stdout);

/************************End Of Template*************************/
ll tot[200005] , cnt[200005] , col[200005] , com = 0;
ll ans = MAX;
int main()
{
	int n , c;
	cin >> n >> c;
	for(int i = 1; i <= n; i++){
		cin >> col[i];
	}
	for(int i = 1; i <= c; i++) {
		cin >> tot[i];
		com += tot[i];
	}
	ll yes = com;// need
	int l = 1 , r = 1 , ok = 0;
	while(l <= n){
		while(r <= n && com > 0){
			if(cnt[col[r]] < tot[col[r]]){// what we need is less than we have
				com--;// need to be added so sub-1
			}
			cnt[col[r]]++;
			r++;
		}
		if(com == 0){//satisfied
			ll rng = (r - l) - yes;// extra after need will be ams
			ans = min(ans , rng );
			ok = 1;
		}
		if(cnt[col[l]] == tot[col[l]]) com++;
		cnt[col[l]]--;
		l++;
	}
	if(!ok) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
using namespace std;

int n, m;
int t[101010];
int req[101010];

deque<int> idx[101010];
int train[101010];
set<int> mi;

void del(int k) {
	int e = idx[k].front();
	idx[k].pop_front();
	mi.erase(mi.find(e));
}

void add(int k, int v) {
	idx[k].push_back(v);
	mi.insert(v);
}

int small() {
	return *mi.begin();
}

int best = 2147483647;
int desire = 0, curr = 0;
bool met = false;

void calc(int r) {
	int l = small();
	//cout << "l,r = ("<<l<<","<<r<<")\n";
	best = min(best, r-l+1-desire);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	FOR(i, 1, n + 1) cin >> t[i];
	int r = 0;
	FOR(i, 1, m + 1) {
		int h; cin >> h;
		req[i] = h;
		desire += h;
		if (h != 0) r++;
	}
	FOR(i, 1, n + 1) {
		// t[i]
		int k = t[i];
		train[k]++;
		if (train[k] == req[k]) curr++;
		add(k, i); // add the index to the link

		if (train[k] > req[k]) {
			// link size of <k> exceeded
			// delete from front
			train[k] = req[k];
			del(k);
		}

		if (curr == r) {
			calc(i);
			met = true;
		}
	}

	if (curr != r) cout << -1;
	else cout << best;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
using namespace std;

int n, m;
int t[101010];
int req[101010];

deque<int> idx[101010];
int train[101010];
set<int> mi;

void del(int k) {
	int e = idx[k].front();
	idx[k].pop_front();
	mi.erase(mi.find(e));
}

void add(int k, int v) {
	idx[k].push_back(v);
	mi.insert(v);
}

int small() {
	return *mi.begin();
}

int best = 2147483647;
int desire = 0, curr = 0;
bool met = false;

void calc(int r) {
	int l = small();
	cout << "l,r = ("<<l<<","<<r<<")\n";
	best = min(best, r-l+1-desire);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	FOR(i, 1, n + 1) cin >> t[i];
	FOR(i, 1, m + 1) {cin >> req[i];desire += req[i];}
	FOR(i, 1, n + 1) {
		// t[i]
		int k = t[i];
		train[k]++;
		if (train[k] == req[k]) curr++;
		add(k, i); // add the index to the link

		if (train[k] > req[k]) {
			// link size of <k> exceeded
			// delete from front
			train[k] = req[k];
			del(k);
		}

		if (curr == m) {
			calc(i);
			met = true;
		}
	}

	if (best == 2147483647) cout << -1;
	else cout << best;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
using namespace std;

int n, m;
int t[101010];
int req[101010];

deque<int> idx[101010];
int train[101010];
set<int> mi;

void del(int k) {
	int e = idx[k].front();
	idx[k].pop_front();
	mi.erase(mi.find(e));
}

void add(int k, int v) {
	idx[k].push_back(v);
	mi.insert(v);
}

int small() {
	return *mi.begin();
}

int best = 2147483647;
int desire = 0, curr = 0;
bool met = false;

void calc(int r) {
	int l = small();
	//cout << "l,r = ("<<l<<","<<r<<")\n";
	best = min(best, r-l+1-desire);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	FOR(i, 1, n + 1) cin >> t[i];
	FOR(i, 1, m + 1) {cin >> req[i];desire += req[i];}
	FOR(i, 1, n + 1) {
		// t[i]
		int k = t[i];
		train[k]++;
		if (train[k] == req[k]) curr++;
		add(k, i); // add the index to the link

		if (train[k] > req[k]) {
			// link size of <k> exceeded
			// delete from front
			train[k] = req[k];
			del(k);
		}

		if (curr == m) {
			calc(i);
			met = true;
		}
	}

	cout << best;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
using namespace std;
#define N 200003

int n, m;
int t[N];
int req[N];

deque<int> idx[N];
int train[N];
set<int> mi;

void del(int k) {
	int e = idx[k].front();
	idx[k].pop_front();
	mi.erase(mi.find(e));
}

void add(int k, int v) {
	idx[k].push_back(v);
	mi.insert(v);
}

int small() {
	return *mi.begin();
}

int best = 2147483647;
int desire = 0, curr = 0;
bool met = false;

void calc(int r) {
	int l = small();
	//cout << "l,r = ("<<l<<","<<r<<")\n";
	best = min(best, r-l+1-desire);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	FOR(i, 1, n + 1) cin >> t[i];
	int r = 0;
	FOR(i, 1, m + 1) {
		int h; cin >> h;
		req[i] = h;
		desire += h;
		if (h != 0) r++;
	}
	FOR(i, 1, n + 1) {
		// t[i]
		int k = t[i];
		train[k]++;
		if (train[k] == req[k]) curr++;
		add(k, i); // add the index to the link

		if (train[k] > req[k]) {
			// link size of <k> exceeded
			// delete from front
			train[k] = req[k];
			del(k);
		}

		if (curr == r) {
			calc(i);
			met = true;
		}
	}

	if (curr != r) cout << -1;
	else cout << best;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
using namespace std;

int n, m;
int t[101010];
int req[101010];

deque<int> idx[101010];
int train[101010];
set<int> mi;

void del(int k) {
	int e = idx[k].front();
	idx[k].pop_front();
	mi.erase(mi.find(e));
}

void add(int k, int v) {
	idx[k].push_back(v);
	mi.insert(v);
}

int small() {
	return *mi.begin();
}

int best = 2147483647;
int desire = 0, curr = 0;
bool met = false;

void calc(int r) {
	int l = small();
	//cout << "l,r = ("<<l<<","<<r<<")\n";
	best = min(best, r-l+1-desire);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	FOR(i, 1, n + 1) cin >> t[i];
	FOR(i, 1, m + 1) {cin >> req[i];desire += req[i];}
	FOR(i, 1, n + 1) {
		// t[i]
		int k = t[i];
		train[k]++;
		if (train[k] == req[k]) curr++;
		add(k, i); // add the index to the link

		if (train[k] > req[k]) {
			// link size of <k> exceeded
			// delete from front
			train[k] = req[k];
			del(k);
		}

		if (curr == m) {
			calc(i);
			met = true;
		}
	}

	if (best == 2147483647) cout << -1;
	else cout << best;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sf1(a)                scanf("%d", &a)
#define sf2(a,b)              scanf("%d %d",&a, &b)
#define sf3(a,b,c)            scanf("%d %d %d", &a, &b, &c)
#define sf4(a,b,c,d)          scanf("%d %d %d %d", &a, &b, &c, &d)

#define sf1ll(a)              scanf("%I64d", &a)
#define sf2ll(a,b)            scanf("%lld %lld", &a, &b)
#define sf3ll(a,b,c)          scanf("%I64d %I64d %I64d", &a, &b, &c)
#define sf4ll(a,b,c,d)        scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d)
int freq[500005] , tst[500005];
pair < int , int > pr ;
int main()
{ fast
  int n , m , tk ;
  sf2(n,m);
  long long sum = 0 ;
  vector < int > vc;
  for (int i = 0 ; i < n ;i++)
    sf1(tk),vc.push_back(tk),tst[tk]++;
  for (int i = 1 ; i<=m;i++ )
    sf1(tk),freq[i]=tst[i]-tk,sum += tk;

   if (!accumulate(tst,tst+n,0) ) exit(puts("0"));
   if (sum > vc.size()) exit(puts("-1"));
   int l = 0 , r = n-1 ;
    // cout << freq[vc[l]] << " " << freq[vc[r]];
   while (l<= r && (freq[vc[l]] || freq[vc[r]] )){
     if (freq[vc[l]]) freq[vc[l]]--,l++;
     if(freq[vc[r]]) freq[vc[r]]--,r--;
   }
   cout << abs ((r-l+1) -sum);
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sf1(a)                scanf("%d", &a)
#define sf2(a,b)              scanf("%d %d",&a, &b)
#define sf3(a,b,c)            scanf("%d %d %d", &a, &b, &c)
#define sf4(a,b,c,d)          scanf("%d %d %d %d", &a, &b, &c, &d)

#define sf1ll(a)              scanf("%I64d", &a)
#define sf2ll(a,b)            scanf("%lld %lld", &a, &b)
#define sf3ll(a,b,c)          scanf("%I64d %I64d %I64d", &a, &b, &c)
#define sf4ll(a,b,c,d)        scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d)
int freq[500005] , vc[500005],tst[500005];
pair < int , int > pr ;
int main()
{ fast
  int n , m , tk,res=0,ans=1e9,l=0 ;
  sf2(n,m);
  long long sum = 0,c=0 ;
  for (int i = 1 ; i <= n ;i++)
    scanf("%d",vc+i);
  for (int i = 1 ; i<=m;i++ )
    {scanf("%d",freq+i),sum += freq[i];if (!freq[i])c++;}

  if ( sum == 0 ) exit(puts("0"));
   //if (sum > n) exit(puts("-1"));

    // cout << freq[vc[l]] << " " << freq[vc[r]];
   for(int i = 1; i <= n; i ++){
            tst[vc[i]]++;
            if(tst[vc[i]] == freq[vc[i]]) c++;
            while(tst[vc[l + 1]] - 1 >= freq[vc[l + 1]]){
                  l++;
                  tst[vc[l]]--;
            }
            if(c == m)
                  ans = min((long long )ans, i - l - sum);
      }
   if (ans == (int)1e9 ) exit(puts("-1"));
   printf("%d",ans);
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sf1(a)                scanf("%d", &a)
#define sf2(a,b)              scanf("%d %d",&a, &b)
#define sf3(a,b,c)            scanf("%d %d %d", &a, &b, &c)
#define sf4(a,b,c,d)          scanf("%d %d %d %d", &a, &b, &c, &d)

#define sf1ll(a)              scanf("%I64d", &a)
#define sf2ll(a,b)            scanf("%lld %lld", &a, &b)
#define sf3ll(a,b,c)          scanf("%I64d %I64d %I64d", &a, &b, &c)
#define sf4ll(a,b,c,d)        scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d)
int freq[500005] , tst[500005];
pair < int , int > pr ;
int main()
{ fast
  int n , m , tk ;
  sf2(n,m);
  long long sum = 0 ;
  vector < int > vc;
  for (int i = 0 ; i < n ;i++)
    sf1(tk),vc.push_back(tk),tst[tk]++;
  for (int i = 1 ; i<=m;i++ )
    sf1(tk),freq[i]=tst[i]-tk,sum += tk;

  // if (!accumulate(tst,tst+n,0) ) exit(puts("0"));
   if (sum > vc.size()) exit(puts("-1"));
   int l = 0 , r = n-1 ;
    // cout << freq[vc[l]] << " " << freq[vc[r]];
   while (l<= r && (freq[vc[l]] || freq[vc[r]] )){
     if (freq[vc[l]]) freq[vc[l]]--,l++;
     if(freq[vc[r]]) freq[vc[r]]--,r--;
   }
   if (l > r || r-l+1 < sum ) exit(puts("-1"));
   cout << abs ((r-l+1) -sum);
}


#include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
const int MAXN = 200005;
const ll MOD = 1000000007;
const double eps = 1e-10;

ll jedi[MAXN];
ll query[MAXN];
ll has[MAXN];
ll all,need,nowHave;

int main(){
    int n,m;
    scanf("%d%d", &n, &m);

    for(int i=1;i<=n;i++){
        scanf("%lld", &jedi[i]);
    }

    for(int i=1;i<=m;i++){
        scanf("%lld", &query[i]);
        all += query[i];
    }
    need = all;

    ll ans=MAXN;

    int i=1,j=1;
    for(j;j<=n;j++){
        nowHave++;
        if(has[jedi[j]]<query[jedi[j]]){
            need--;
        }
        has[jedi[j]]++;
        for(i;i<=j;){
            if(need==0){
                ans = min(ans, nowHave-all);
                has[jedi[i]]--;
                if(has[jedi[i]]<query[jedi[i]]){
                    need++;
                }
                nowHave--;
                i++;
            }
            else break;
        }
    }

    if (ans == MAXN)ans = -1;
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define sz(a) (ll) a.size()
#define ff first
#define ss second
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define oo 1e18
#define pi pair<ll, ll>
#define all(x) x.begin(), x.end()
const ll mod = 998244353ll;
const ll P = 1000000009ll;
const ll N = 200005ll;

bool cmp(pair<pi, bool> x, pair<pi, bool> y)
{
  return x.ff.ff > y.ff.ff;
}
ll a[N], b[N], c[N];
void solve()
{
  ll n, m;
  cin >> n >> m;
  ll ans = oo;

  rep(i, 1, n) cin >> a[i];
  ll sum = 0;
  ll m1 = m;
  rep(i, 1, m1)
  {
    cin >> b[i];
    sum += b[i];
    if (b[i] == 0)
      m--;
  }
  ll prev = 0;

  rep(i, 1, n)
  {
    ++c[a[i]];

    if (c[a[i]] == b[a[i]])
      m--;
  //  cout << "m " << m << "  ";

      while (c[a[prev + 1]] > b[a[prev + 1]])
      {
        prev++;
        --c[a[prev]];
      }
    if(m==0){
      ans = min(ans, i - prev - sum);
      prev++;
      --c[prev];
      ++m;
    //  cout << i << " " << ans << "    ";
    }
  }

  if (ans == oo)
    cout << -1;
  else
    cout << ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

//  freopen("input.txt", "r", stdin);
 // freopen("output.txt", "w", stdout);

  ll t = 1;
  // cin >> t;
  while (t--)
  {
    solve();
    cout << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define sz(a) (ll) a.size()
#define ff first
#define ss second
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define oo 1e18
#define pi pair<ll, ll>
#define all(x) x.begin(), x.end()
const ll mod = 998244353ll;
const ll P = 1000000009ll;
const ll N = 200005ll;

bool cmp(pair<pi, bool> x, pair<pi, bool> y)
{
  return x.ff.ff > y.ff.ff;
}
ll a[N], b[N], c[N];
void solve()
{
  ll n, m;
  cin >> n >> m;
  ll ans = oo;

  rep(i, 1, n) cin >> a[i];
  ll sum = 0;
  rep(i, 1, m)
  {
    cin >> b[i];
    sum += b[i];
    if (b[i] == 0)
      m--;
  }
  ll prev = 0;

  rep(i, 1, n)
  {
    ++c[a[i]];

    if (c[a[i]] == b[a[i]])
      m--;
   // cout << "m " << m << "  ";
    if (m == 0)
    {
      while (c[a[prev + 1]] > b[a[prev + 1]])
      {
        prev++;
        --c[a[prev]];
      }

      ans = min(ans, i - prev - sum);
      prev++;
      --c[prev];
      ++m;
      //cout << i << " " << ans << "    ";
    }
  }

  if (ans == oo)
    cout << -1;
  else
    cout << ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

//  freopen("input.txt", "r", stdin);
 // freopen("output.txt", "w", stdout);

  ll t = 1;
  // cin >> t;
  while (t--)
  {
    solve();
    cout << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define sz(a) (ll) a.size()
#define ff first
#define ss second
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define oo 1e18
#define pi pair<ll, ll>
#define all(x) x.begin(), x.end()
const ll mod = 998244353ll;
const ll P = 1000000009ll;
const ll N = 200005ll;

bool cmp(pair<pi, bool> x, pair<pi, bool> y)
{
  return x.ff.ff > y.ff.ff;
}
ll a[N], b[N], c[N];
void solve()
{
  ll n, m;
  cin >> n >> m;
  ll ans = oo;

  rep(i, 1, n) cin >> a[i];
  ll sum = 0;
  ll m1 = m;
  rep(i, 1, m1)
  {
    cin >> b[i];
    sum += b[i];
    if (b[i] == 0)
      m--;
  }
  ll prev = 0;

  rep(i, 1, n)
  {
    ++c[a[i]];

    if (c[a[i]] == b[a[i]])
      m--;
  //  cout << "m " << m << "  ";
    if (m == 0)
    {
      while (c[a[prev + 1]] > b[a[prev + 1]])
      {
        prev++;
        --c[a[prev]];
      }

      ans = min(ans, i - prev - sum);
      prev++;
      --c[prev];
      ++m;
    //  cout << i << " " << ans << "    ";
    }
  }

  if (ans == oo)
    cout << -1;
  else
    cout << ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

//  freopen("input.txt", "r", stdin);
 // freopen("output.txt", "w", stdout);

  ll t = 1;
  // cin >> t;
  while (t--)
  {
    solve();
    cout << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define sz(a) (ll) a.size()
#define ff first
#define ss second
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define oo 1e18
#define pi pair<ll, ll>
#define all(x) x.begin(), x.end()
const ll mod = 998244353ll;
const ll P = 1000000009ll;
const ll N = 200005ll;

bool cmp(pair<pi, bool> x, pair<pi, bool> y)
{
  return x.ff.ff > y.ff.ff;
}
ll a[N], b[N], c[N];
void solve()
{
  ll n, m;
  cin >> n >> m;
  ll ans = oo;

  rep(i, 1, n) cin >> a[i];
  ll sum = 0;
  ll m1 = m;
  rep(i, 1, m1)
  {
    cin >> b[i];
    sum += b[i];
    if (b[i] == 0)
      m--;
  }
  ll prev = 0;

  rep(i, 1, n)
  {
    ++c[a[i]];

    if (c[a[i]] == b[a[i]])
      m--;
  //  cout << "m " << m << "  ";
    if(m == 0){
      while (c[a[prev + 1]] > b[a[prev + 1]])
      {
        prev++;
        --c[a[prev]];
      }

      ans = min(ans, i - prev - sum);
    //  cout << i << " " << ans << "    ";
    }
  }

  if (ans == oo)
    cout << -1;
  else
    cout << ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

//  freopen("input.txt", "r", stdin);
 // freopen("output.txt", "w", stdout);

  ll t = 1;
  // cin >> t;
  while (t--)
  {
    solve();
    cout << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define sz(a) (ll) a.size()
#define ff first
#define ss second
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define oo 1e18
#define pi pair<ll, ll>
#define all(x) x.begin(), x.end()
const ll mod = 998244353ll;
const ll P = 1000000009ll;
const ll N = 200005ll;

bool cmp(pair<pi, bool> x, pair<pi, bool> y)
{
  return x.ff.ff > y.ff.ff;
}
ll a[N], b[N], c[N];
void solve()
{
  ll n, m;
  cin >> n >> m;
  ll ans = oo;

  rep(i, 1, n) cin >> a[i];
  ll sum = 0;
  ll m1 = m;
  rep(i, 1, m1)
  {
    cin >> b[i];
    sum += b[i];
    if (b[i] == 0)
      m--;
  }
  ll prev = 0;

  rep(i, 1, n)
  {
    ++c[a[i]];

    if (c[a[i]] == b[a[i]])
      m--;
  //  cout << "m " << m << "  ";

      while (c[a[prev + 1]] > b[a[prev + 1]])
      {
        prev++;
        --c[a[prev]];
      }
    if(m==0){
      ans = min(ans, i - prev - sum);
      prev++;
      --c[a[prev]];
      ++m;
    //  cout << i << " " << ans << "    ";
    }
  }

  if (ans == oo)
    cout << -1;
  else
    cout << ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

//  freopen("input.txt", "r", stdin);
 // freopen("output.txt", "w", stdout);

  ll t = 1;
  // cin >> t;
  while (t--)
  {
    solve();
    cout << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define sz(a) (ll) a.size()
#define ff first
#define ss second
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define oo 1e18
#define pi pair<ll, ll>
#define all(x) x.begin(), x.end()
const ll mod = 998244353ll;
const ll P = 1000000009ll;
const ll N = 200005ll;

bool cmp(pair<pi, bool> x, pair<pi, bool> y)
{
  return x.ff.ff > y.ff.ff;
}
ll a[N], b[N], c[N];
void solve()
{
  ll n, m;
  cin >> n >> m;
  ll ans = oo;

  rep(i, 1, n) cin >> a[i];
  ll sum = 0;
  ll m1 = m;
  rep(i, 1, m1)
  {
    cin >> b[i];
    sum += b[i];
    if (b[i] == 0)
      m--;
  }
  ll prev = 0;

  rep(i, 1, n)
  {
    ++c[a[i]];

    if (c[a[i]] == b[a[i]])
      m--;
  //  cout << "m " << m << "  ";
    if (m == 0)
    {
      while (prev<i&&c[a[prev + 1]] > b[a[prev + 1]])
      {
        prev++;
        --c[a[prev]];
      }

      ans = min(ans, i - prev - sum);
      prev++;
      --c[prev];
      ++m;
    //  cout << i << " " << ans << "    ";
    }
  }

  if (ans == oo)
    cout << -1;
  else
    cout << ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

//  freopen("input.txt", "r", stdin);
 // freopen("output.txt", "w", stdout);

  ll t = 1;
  // cin >> t;
  while (t--)
  {
    solve();
    cout << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define sz(a) (ll) a.size()
#define ff first
#define ss second
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define oo 1e18
#define pi pair<ll, ll>
#define all(x) x.begin(), x.end()
const ll mod = 998244353ll;
const ll P = 1000000009ll;
const ll N = 200005ll;

bool cmp(pair<pi, bool> x, pair<pi, bool> y)
{
  return x.ff.ff > y.ff.ff;
}
ll a[N], b[N], c[N];
void solve()
{
  ll n, m;
  cin >> n >> m;
  ll ans = oo;

  rep(i, 1, n) cin >> a[i];
  ll sum = 0;
  ll m1 = m;
  rep(i, 1, m1)
  {
    cin >> b[i];
    sum += b[i];
    if (b[i] == 0)
      m--;
  }
  ll prev = 0;

  rep(i, 1, n)
  {
    ++c[a[i]];

    if (c[a[i]] == b[a[i]])
      m--;
    while (prev + 1 <= n && c[a[prev + 1]] > b[a[prev + 1]])
    {
      prev++;
      --c[a[prev]];
    }
    if (m == 0)
    {

      ans = min(ans, i - prev - sum);
    }
  }

  if (ans == oo)
    cout << -1;
  else
    cout << ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

 // freopen("input.txt", "r", stdin);
 // freopen("output.txt", "w", stdout);

  ll t = 1;
  // cin >> t;
  while (t--)
  {
    solve();
    cout << "\n";
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    map<ll , ll> m1,m2;
    for(ll i=0;i<m;i++)
    {
        m1[i]=k[i];
        m2[i]=k[i];
    }
    for(ll i=0;i<p;i++)
    {
        m1[a[i]]--;
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
    }
    if(m2.empty())
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        m1[a[i-p]]++;
        if(m1[a[i-p]]>0)
            m2[a[i-p]]=m1[a[i-p]];
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
        m1[a[i]]--;
        if(m2.empty())
        {
            return true;
        }
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return mid;
}
int main()
{
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>k[i];
        ans+=k[i];
    }
    if(!check(a,k,n,m,n))
        cout<<"-1";
    else
        cout<<bs(a,k,n,m)-ans;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    int c[m];
    for(int i=0; i<m; i++)
        c[i]=k[i];
    int nz=m;
    for(ll i=0;i<p;i++)
    {
        c[a[i]]--;
        if(c[a[i]]==0)
            nz--;
    }
    if(nz==0)
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        c[a[i-p]]++;
        if(c[a[i-p]]==1)
            nz++;
        c[a[i]]--;
        if(c[a[i]]==0)
            nz--;
        if(nz==0)
            return true;
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return e;
}
int main()
{
    srand(time(NULL));
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>k[i];
        ans+=k[i];
    }
    // int p;
    // cin>>p;
    // cout<<check(a,k,n,m,p)<<"\n";=0
    // int prefix[n+1][m] = {{0}};
    // for (int i = 1; i < n; ++i)
    // {
    //     prefix[i][a[i-1]-1]++;
    //     for(int j=0; j<m; j++)
    //     {
    //         prefix[i][j]+=prefix[i-1][j];
    //     }
    // }
    // int minv=1000000;
    // for (int i = 0; i <= n; ++i)
    // {
    //     for (int j = i+1; j <= n; ++j)
    //     {
    //         bool pos=true;
    //         for(int l=0; l<m; l++)
    //         {
    //             if(k[l]>prefix[j][l]-prefix[i][l])
    //                 pos=false;
    //         }
    //         if(pos)
    //             minv=min(minv, j-i+1);
    //     }
    // }
    // if(bs(a,k,n,m)-ans!=minv-ans)
    // {
    //     cout<<n<<" "<<m<<"\n";
    //     for(int i=0; i<n; i++)
    //         cout<<a[i]<<" ";
    //     cout<<"\n";
    //     for(int i=0; i<m; i++)
    //         cout<<k[i]<<" ";
    //         cout<<endl;
    //     cout<<minv<<" "<<bs(a,k,n,m)-ans;
    // }
     if(!check(a,k,n,m,n))
         cout<<"-1";
     else
         cout<<bs(a,k,n,m)-ans;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    map<ll , ll> m1,m2;
    for(ll i=0;i<m;i++)
    {
        m1[i]=k[i];
        m2[i]=k[i];
    }
    for(ll i=0;i<p;i++)
    {
        m1[a[i]]--;
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
    }
    if(m2.empty())
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        m1[a[i-p]]++;
        if(m1[a[i-p]]>0)
            m2[a[i-p]]=m1[a[i-p]];
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
        m1[a[i]]--;
        if(m2.empty())
        {
            return true;
        }
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return mid;
}
int main()
{
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>k[i];
        ans+=k[i];
    }
    if(!check(a,k,n,m,n))
        cout<<"- 1";
    else
        cout<<bs(a,k,n,m)-ans;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    map<ll , ll> m1,m2;
    for(ll i=0;i<m;i++)
    {
        m1[i]=k[i];
        m2[i]=k[i];
        if(m2[i]==0)
        m2.erase(i);
    }
    for(ll i=0;i<p;i++)
    {
        m1[a[i]]--;
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
    }
    if(m2.empty())
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        m1[a[i-p]]++;
        if(m1[a[i-p]]>0)
            m2[a[i-p]]=m1[a[i-p]];
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
        m1[a[i]]--;
        if(m2.empty())
        {
            return true;
        }
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return mid;
}
int main()
{
    fastio;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "rt", stdin);
    //     freopen("output.txt", "wt", stdout);
    // #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>k[i];
        ans+=k[i];
    }
    if(!check(a,k,n,m,n))
        cout<<"-1";
    else
        cout<<bs(a,k,n,m)-ans;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    int c[m];
    int nz=0;
    for(int i=0; i<m; i++)
    {
        c[i]=k[i];
        if(c[i]!=0)
            nz++;
    }
    for(ll i=0;i<p;i++)
    {
        c[a[i]]--;
        if(c[a[i]]==0)
            nz--;
    }
    if(nz==0)
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        c[a[i-p]]++;
        if(c[a[i-p]]==1)
            nz++;
        c[a[i]]--;
        if(c[a[i]]==0)
            nz--;
        if(nz==0)
            return true;
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return e;
}
int main()
{
    srand(time(NULL));
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>k[i];
        ans+=k[i];
    }
    // int p;
    // cin>>p;
    // cout<<check(a,k,n,m,p)<<"\n";=0
    // int prefix[n+1][m] = {{0}};
    // for (int i = 1; i < n; ++i)
    // {
    //     prefix[i][a[i-1]-1]++;
    //     for(int j=0; j<m; j++)
    //     {
    //         prefix[i][j]+=prefix[i-1][j];
    //     }
    // }
    // int minv=1000000;
    // for (int i = 0; i <= n; ++i)
    // {
    //     for (int j = i+1; j <= n; ++j)
    //     {
    //         bool pos=true;
    //         for(int l=0; l<m; l++)
    //         {
    //             if(k[l]>prefix[j][l]-prefix[i][l])
    //                 pos=false;
    //         }
    //         if(pos)
    //             minv=min(minv, j-i+1);
    //     }
    // }
    // if(bs(a,k,n,m)-ans!=minv-ans)
    // {
    //     cout<<n<<" "<<m<<"\n";
    //     for(int i=0; i<n; i++)
    //         cout<<a[i]<<" ";
    //     cout<<"\n";
    //     for(int i=0; i<m; i++)
    //         cout<<k[i]<<" ";
    //         cout<<endl;
    //     cout<<minv<<" "<<bs(a,k,n,m)-ans;
    // }
     if(!check(a,k,n,m,n))
         cout<<"-1";
     else
         cout<<bs(a,k,n,m)-ans;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    map<ll , ll> m1,m2;
    for(ll i=0;i<m;i++)
    {
        m1[i]=k[i];
        m2[i]=k[i];
    }
    for(ll i=0;i<p;i++)
    {
        m1[a[i]]--;
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
    }
    if(m2.empty())
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        m1[a[i-p]]++;
        if(m1[a[i-p]]>0)
            m2[a[i-p]]=m1[a[i-p]];
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
        m1[a[i]]--;
        if(m2.empty())
        {
            return true;
        }
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return e;
}
int main()
{
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>k[i];
        ans+=k[i];
    }
    // int p;
    // cin>>p;

    // cout<<check(a,k,n,m,p)<<"\n";
    if(!check(a,k,n,m,n))
        cout<<"-1";
    else
        cout<<bs(a,k,n,m)-ans;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    map<ll , ll> m1,m2;
    for(ll i=0;i<m;i++)
    {
        m1[i]=k[i];
        m2[i]=k[i];
    }
    for(ll i=0;i<p;i++)
    {
        m1[a[i]]--;
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
    }
    if(m2.empty())
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        m1[a[i-p]]++;
        if(m1[a[i-p]]>0)
            m2[a[i-p]]=m1[a[i-p]];
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
        m1[a[i]]--;
        if(m2.empty())
        {
            return true;
        }
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return mid;
}
int main()
{
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>k[i];
        ans+=k[i];
    }
    int p;
    cin>>p;
    if(!check(a,k,n,m,n))
        cout<<"- 1";
    else
        cout<<bs(a,k,n,m)-ans;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    map<ll , ll> m1,m2;
    for(ll i=0;i<m;i++)
    {
        m1[i]=k[i];
        m2[i]=k[i];
    }
    for(ll i=0;i<p;i++)
    {
        m1[a[i]]--;
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
    }
    if(m2.empty())
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        m1[a[i-p]]++;
        if(m1[a[i-p]]>0)
            m2[a[i-p]]=m1[a[i-p]];
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
        m1[a[i]]--;
        if(m2.empty())
        {
            return true;
        }
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return mid;
}
int main()
{
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    for(ll i=0;i<m;i++)
        cin>>k[i];
    cout<<bs(a,k,n,m);
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
inline bool check(ll a[],ll k[],ll n,ll m, ll p)
{
    map<ll , ll> m1,m2;
    for(ll i=0;i<m;i++)
    {
        m1[i]=k[i];
        m2[i]=k[i];
    }
    for(ll i=0;i<p;i++)
    {
        m1[a[i]]--;
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
    }
    if(m2.empty())
    {
        return true;
    }
    for(ll i=p;i<n;i++)
    {
        m1[a[i-p]]++;
        if(m1[a[i-p]]>0)
            m2[a[i-p]]=m1[a[i-p]];
        m2[a[i]]--;
        if(m2[a[i]]<=0)
            m2.erase(a[i]);
        m1[a[i]]--;
        if(m2.empty())
        {
            return true;
        }
    }
    return false;
}
inline  ll bs(ll a[],ll k[],ll n,ll m)
{
    ll s=0,e=n,mid=(s+e)/2;
    while(s<e)
    {
        if(check(a,k,n,m,mid))
            e=mid;
        else
            s=mid+1;
        mid=(s+e)/2;
    }
    return mid;
}
int main()
{
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ll n,m;
    cin>>n>>m;
    ll a[n],k[m];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    ll ans=0;
    for(ll i=0;i<m;i++)
    {
        cin>>k[i];
        ans+=k[i];
    }
    cout<<bs(a,k,n,m)-ans;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{
	fio;

	ll t,i,j,n,m,l,r,ta,tb,k,x,cl,ce,v,q,x1,y1,x2,y2;

    cin>>n>>m;
    ll arr1[n+1];
    ll arr2[m+1];
    set<ll>s2;
    for(i=1;i<=n;i++)
    {
    	cin>>arr1[i];
    	s2.insert(arr1[i]);
	}
	set<ll>s3;
	for(i=1;i<=m;i++)
	{
		cin>>arr2[i];
		if(arr2[i]>0)
		s3.insert(i);
	}

	ll low=0,high=n,ans=-1;
	while(low<=high)
	{
			set<ll>s,s4;
		for(i=1;i<=m;i++)
		{
			if(s2.find(i)==s2.end()&&arr2[i]==0)
			s.insert(i);
		}
		ll mid=(low+high)>>1;
		i=1,j=1;

		ll count=0;
		ll mpp[m+1]={0};
		ll flag=0;
		while(i<=n&&j<=n)
		{
			mpp[arr1[j]]++;

			if(mpp[arr1[j]]>=arr2[arr1[j]])
			{

				if(s3.find(arr1[j])!=s3.end())
				s4.insert(arr1[j]);

			}

		   if(s4.size()==s3.size())
		   {
		   	flag=1;
		   	break;
		   }

			if(mpp[arr1[j]]>arr2[arr1[j]])

			{

				if(count<mid)
				{
					count++;
				}
				else
				{
					while(true)
					{
						if(mpp[arr1[i]]>arr2[arr1[i]])
						{

									mpp[arr1[i]]--;
							i++;
								break;

						}
						else
						{
							mpp[arr1[i]]--;
							if(mpp[arr1[i]]<arr2[arr1[i]])
							{
								if(s3.find(arr1[i])!=s3.end())
								s4.erase(arr1[i]);

							}

							i++;
						}
					}

				}

			}

			j++;
		//	cout<<i<<" "<<j<<" "<<s.size()<<endl;

		}
		if(flag==1)
		{
			ans=mid;
			high=mid-1;
		}
		else
		low=mid+1;

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{
	fio;

	ll t,i,j,n,m,l,r,ta,tb,k,x,cl,ce,v,q,x1,y1,x2,y2;

    cin>>n>>m;
    ll arr1[n+1];
    ll arr2[m+1];
    set<ll>s2;
    for(i=1;i<=n;i++)
    {
    	cin>>arr1[i];
    	s2.insert(arr1[i]);
	}
	for(i=1;i<=m;i++)
	{
		cin>>arr2[i];
	}

	ll low=0,high=n,ans=-1;
	while(low<=high)
	{
			set<ll>s;
		for(i=1;i<=m;i++)
		{
			if(s2.find(i)==s2.end()&&arr2[i]==0)
			s.insert(i);
		}
		ll mid=(low+high)>>1;
		i=1,j=1;

		ll count=0;
		map<ll,ll>mpp;
		ll flag=0;
		while(i<=n&&j<=n)
		{
			mpp[arr1[j]]++;

			if(mpp[arr1[j]]>=arr2[arr1[j]])
			s.insert(arr1[j]);
		//	cout<<i<<" "<<j<<" "<<s.size()<<endl;
	         if(arr2[arr1[j]]==0)
				{
					if(s.size()==m)
					{
						flag=1;
						break;
					}
					j++;
					continue;
				}

			if(mpp[arr1[j]]>arr2[arr1[j]])

			{

				if(count<mid)
				{
					count++;
				}
				else
				{
					while(true)
					{
						if(mpp[arr1[i]]>arr2[arr1[i]])
						{
						//	count--;
						    if(arr2[arr1[i]]==0)
						    {
						    		mpp[arr1[i]]--;
							i++;
							}
							else
							{
									mpp[arr1[i]]--;
							i++;
								break;
							}

						}
						else
						{
							mpp[arr1[i]]--;
							if(mpp[arr1[i]]<arr2[arr1[i]])
							s.erase(arr1[i]);
							i++;
						}
					}

				}

			}
			if(s.size()==m)
			{
				flag=1;
				break;
			}
			j++;
		//	cout<<i<<" "<<j<<" "<<s.size()<<endl;

		}
		if(flag==1)
		{
			ans=mid;
			high=mid-1;
		}
		else
		low=mid+1;

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{
	fio;

	ll t,i,j,n,m,l,r,ta,tb,k,x,cl,ce,v,q,x1,y1,x2,y2;

    cin>>n>>m;
    ll arr1[n+1];
    ll arr2[m+1];
    set<ll>s2;
    for(i=1;i<=n;i++)
    {
    	cin>>arr1[i];
    	s2.insert(arr1[i]);
	}
	set<ll>s3;
	for(i=1;i<=m;i++)
	{
		cin>>arr2[i];
		if(arr2[i]>0)
		s3.insert(i);
	}
	ll val=s3.size();

	ll low=0,high=n,ans=-1;
	while(low<=high)
	{

	    ll count2=0;
		ll mid=(low+high)>>1;
		i=1,j=1;

		ll count=0;
		ll mpp[m+1]={0};
		ll mpp2[m+1]={0};
		ll flag=0;
		while(i<=n&&j<=n)
		{
			mpp[arr1[j]]++;

			if(mpp[arr1[j]]==arr2[arr1[j]])
			{

			   	if(arr2[arr1[j]]!=0)
			   	{

			   	count2++;
			   }
			   }

		   if(count2==val)
		   {
		   	flag=1;
		   	break;
		   }

			if(mpp[arr1[j]]>arr2[arr1[j]])

			{

				if(count<mid)
				{
					count++;
				}
				else
				{
					while(true)
					{
						if(mpp[arr1[i]]>arr2[arr1[i]])
						{

									mpp[arr1[i]]--;
							i++;
								break;

						}
						else
						{
							mpp[arr1[i]]--;
							if(mpp[arr1[i]]<arr2[arr1[i]])
							{
							   if(arr2[arr1[i]]!=0)
							   {
							   	count2--;
							   }

							}

							i++;
						}
					}

				}

			}

			j++;
		//	cout<<i<<" "<<j<<" "<<s.size()<<endl;

		}
		if(flag==1)
		{
			ans=mid;
			high=mid-1;
		}
		else
		low=mid+1;

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{
	fio;

	ll t,i,j,n,m,l,r,ta,tb,k,x,cl,ce,v,q,x1,y1,x2,y2;

    cin>>n>>m;
    ll arr1[n+1];
    ll arr2[m+1];
    set<ll>s2;
    for(i=1;i<=n;i++)
    {
    	cin>>arr1[i];
    	s2.insert(arr1[i]);
	}
	set<ll>s3;
	for(i=1;i<=m;i++)
	{
		cin>>arr2[i];
		if(arr2[i]>0)
		s3.insert(i);
	}

	ll low=0,high=n,ans=-1;
	while(low<=high)
	{
			set<ll>s,s4;
		for(i=1;i<=m;i++)
		{
			if(s2.find(i)==s2.end()&&arr2[i]==0)
			s.insert(i);
		}
		ll mid=(low+high)>>1;
		i=1,j=1;

		ll count=0;
		unordered_map<ll,ll>mpp;
		ll flag=0;
		while(i<=n&&j<=n)
		{
			mpp[arr1[j]]++;

			if(mpp[arr1[j]]>=arr2[arr1[j]])
			{
				s.insert(arr1[j]);
				if(s3.find(arr1[j])!=s3.end())
				s4.insert(arr1[j]);

			}

		   if(s4.size()==s3.size())
		   {
		   	flag=1;
		   	break;
		   }

			if(mpp[arr1[j]]>arr2[arr1[j]])

			{

				if(count<mid)
				{
					count++;
				}
				else
				{
					while(true)
					{
						if(mpp[arr1[i]]>arr2[arr1[i]])
						{

									mpp[arr1[i]]--;
							i++;
								break;

						}
						else
						{
							mpp[arr1[i]]--;
							if(mpp[arr1[i]]<arr2[arr1[i]])
							{
								if(s3.find(arr1[i])!=s3.end())
								s4.erase(arr1[i]);
									s.erase(arr1[i]);
							}

							i++;
						}
					}

				}

			}
			if(s.size()==m)
			{
				flag=1;
				break;
			}
			j++;
		//	cout<<i<<" "<<j<<" "<<s.size()<<endl;

		}
		if(flag==1)
		{
			ans=mid;
			high=mid-1;
		}
		else
		low=mid+1;

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{
	fio;

	ll t,i,j,n,m,l,r,ta,tb,k,x,cl,ce,v,q,x1,y1,x2,y2;

    cin>>n>>m;
    ll arr1[n+1];
    ll arr2[m+1];
    set<ll>s2;
    for(i=1;i<=n;i++)
    {
    	cin>>arr1[i];
    	s2.insert(arr1[i]);
	}
	set<ll>s3;
	ll mpp2[m+1]={0};
	for(i=1;i<=m;i++)
	{
		cin>>arr2[i];
		if(arr2[i]>0)
		{
			mpp2[i]=1;
				s3.insert(i);
		}

	}
	ll val=s3.size();

	ll low=0,high=n,ans=-1;
	while(low<=high)
	{
			set<ll>s,s4;
		for(i=1;i<=m;i++)
		{
			if(s2.find(i)==s2.end()&&arr2[i]==0)
			s.insert(i);
		}
		ll mid=(low+high)>>1;
		i=1,j=1;
	    ll c2=0;
	    ll mpp4[m+1]={0};

		ll count=0;
		ll mpp[m+1]={0};
		ll flag=0;
		while(i<=n&&j<=n)
		{
			mpp[arr1[j]]++;

			if(mpp[arr1[j]]>=arr2[arr1[j]])
			{

			    if(mpp2[arr1[j]]==1&&mpp4[arr1[j]]==0)
			    {
			    	mpp4[arr1[j]]=1;
			    	c2++;
				}

			}

		   if(c2==val)
		   {
		   	flag=1;
		   	break;
		   }

			if(mpp[arr1[j]]>arr2[arr1[j]])

			{

				if(count<mid)
				{
					count++;
				}
				else
				{
					while(true)
					{
						if(mpp[arr1[i]]>arr2[arr1[i]])
						{

									mpp[arr1[i]]--;
							i++;
								break;

						}
						else
						{
							mpp[arr1[i]]--;
							if(mpp[arr1[i]]<arr2[arr1[i]])
							{
							   if(mpp2[arr1[i]]==1&&mpp4[arr1[i]]==1)
							   {
							   	mpp4[arr1[i]]=0;
							   	c2--;
							   }

							}

							i++;
						}
					}

				}

			}

			j++;
	//		cout<<i<<" "<<j<<" "<<c2<<endl;

		}
		if(flag==1)
		{
			ans=mid;
			high=mid-1;
		}
		else
		low=mid+1;

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{
	fio;

	ll t,i,j,n,m,l,r,ta,tb,k,x,cl,ce,v,q,x1,y1,x2,y2;

    cin>>n>>m;
    ll arr1[n+1];
    ll arr2[m+1];
    set<ll>s2;
    for(i=1;i<=n;i++)
    {
    	cin>>arr1[i];
    	s2.insert(arr1[i]);
	}
	for(i=1;i<=m;i++)
	{
		cin>>arr2[i];
	}

	ll low=0,high=n,ans=-1;
	while(low<=high)
	{
			set<ll>s;
		for(i=1;i<=m;i++)
		{
			if(s2.find(i)==s2.end()&&arr2[i]==0)
			s.insert(i);
		}
		ll mid=(low+high)>>1;
		i=1,j=1;

		ll count=0;
		map<ll,ll>mpp;
		ll flag=0;
		while(i<=n&&j<=n)
		{
			mpp[arr1[j]]++;

			if(mpp[arr1[j]]>=arr2[arr1[j]])
			s.insert(arr1[j]);
		//	cout<<i<<" "<<j<<" "<<s.size()<<endl;
			if(mpp[arr1[j]]>arr2[arr1[j]])
			{
				if(count<mid)
				{
					count++;
				}
				else
				{
					while(true)
					{
						if(mpp[arr1[i]]>arr2[arr1[i]])
						{
						//	count--;
							mpp[arr1[i]]--;
							i++;
							break;
						}
						else
						{
							mpp[arr1[i]]--;
							if(mpp[arr1[i]]<arr2[arr1[i]])
							s.erase(arr1[i]);
							i++;
						}
					}

				}
			}
			if(s.size()==m)
			{
				flag=1;
				break;
			}
			j++;
		//	cout<<i<<" "<<j<<" "<<s.size()<<endl;

		}
		if(flag==1)
		{
			ans=mid;
			high=mid-1;
		}
		else
		low=mid+1;

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main()
{
	fio;

	ll t,i,j,n,m,l,r,ta,tb,k,x,cl,ce,v,q,x1,y1,x2,y2;

    cin>>n>>m;
    ll arr1[n+1];
    ll arr2[m+1];
    set<ll>s2;
    for(i=1;i<=n;i++)
    {
    	cin>>arr1[i];
    	s2.insert(arr1[i]);
	}
	set<ll>s3;
	for(i=1;i<=m;i++)
	{
		cin>>arr2[i];
		if(arr2[i]>0)
		s3.insert(i);
	}

	ll low=0,high=n,ans=-1;
	while(low<=high)
	{
			set<ll>s,s4;
		for(i=1;i<=m;i++)
		{
			if(s2.find(i)==s2.end()&&arr2[i]==0)
			s.insert(i);
		}
		ll mid=(low+high)>>1;
		i=1,j=1;

		ll count=0;
		map<ll,ll>mpp;
		ll flag=0;
		while(i<=n&&j<=n)
		{
			mpp[arr1[j]]++;

			if(mpp[arr1[j]]>=arr2[arr1[j]])
			{
				s.insert(arr1[j]);
				if(s3.find(arr1[j])!=s3.end())
				s4.insert(arr1[j]);

			}

		   if(s4.size()==s3.size())
		   {
		   	flag=1;
		   	break;
		   }

			if(mpp[arr1[j]]>arr2[arr1[j]])

			{

				if(count<mid)
				{
					count++;
				}
				else
				{
					while(true)
					{
						if(mpp[arr1[i]]>arr2[arr1[i]])
						{

									mpp[arr1[i]]--;
							i++;
								break;

						}
						else
						{
							mpp[arr1[i]]--;
							if(mpp[arr1[i]]<arr2[arr1[i]])
							{
								if(s3.find(arr1[i])!=s3.end())
								s4.erase(arr1[i]);
									s.erase(arr1[i]);
							}

							i++;
						}
					}

				}

			}
			if(s.size()==m)
			{
				flag=1;
				break;
			}
			j++;
		//	cout<<i<<" "<<j<<" "<<s.size()<<endl;

		}
		if(flag==1)
		{
			ans=mid;
			high=mid-1;
		}
		else
		low=mid+1;

	}
	cout<<ans;

}