#include <bits/stdc++.h>

using namespace std;
i
int contador[1005] = {0};

int main(int argc, char const *argv[])
{
	int n, m, d, pts = 0;

	cin >> n >> m;
	int bloco;
	for (int i = 0; i < m; ++i)
	{
		scanf("%d", &bloco);
		contador[bloco]++;
	}

	int ans = 1001;
	for (int i = 1; i <= n; ++i)
	{
		ans = min(ans, contador[i]);
	}

	cout << ans;

	return 0;
}


#include<iostream>
#include<algorithm>
const int maxn=1e9;
using namespace std;
int a[1000];

int main(){
    int n,m,k,ans=maxn;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>k;
        a[k]++;
    }
    for(int i=1;i<=n;i++){
            ans=min(ans,a[i]);
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<algorithm>
const int maxn=1e9;
using namespace std;
int a[1000];

int main(){
    int n,m,k,ans=maxn;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>k;
        a[k]++;
    }
    for(int i=0;i<m;i++){
           if(a[i]!=0){
            ans=min(ans,a[i]);
           }
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<algorithm>
const int maxn=1e9;
using namespace std;
int a[1000];

int main(){
    int n,m,k,ans=maxn;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>k;
        a[k]++;
        if(a[k]>n)a[k]=n;
    }
    for(int i=0;i<m;i++){
           if(a[i]!=0){
            ans=min(ans,a[i]);
           }
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int a[1000];

int main(){
    int n,m,k,min1=1001,ans=1001;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>k;
        a[k]++;
    }
    for(int i=0;i<m;i++){
       if(a[i]!=0)ans=min(ans,a[i]);
    }
    cout<<ans;
    return 0;

}

/*
if(min1>a[i]&&a[i]!=0){
         min1=a[i];
         ans=i;
       }
*/


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int a[m + 1];
	memset(a, 0, sizeof(a));
	for(int i = 1; i <= m; i++)
	{
		int x;
		cin >> x;
		a[x]++;
	}
	int ans = 0x7fffffff;
	for(int i = 1; i <= n; i++)
		if(!a[i])
			ans = min(ans, a[i]);
	cout << ans;
	return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int a[1001];
	memset(a, 0, sizeof(a));
	for(int i = 1; i <= m; i++)
	{
		int x;
		cin >> x;
		a[x]++;
	}
	int ans = 1000;
	for(int i = 1; i <= n; i++)
			ans = min(ans, a[i]);
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int cnt[10010];
	int ans=0x7ffff;
	memset(cnt, 0, sizeof(cnt));
	for(int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		cnt[a]++;
	}
	for(int i = 1; i <= n; i++)
		if(cnt[i] != 0)
			ans = min(ans, cnt[i]);
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,p=INT_MAX,a;
    cin>>n>>m;
    long long int flag[1000000];
    memset(flag,0,sizeof(flag));
    for(i=0;i<m;i++)
    {
        cin>>a;
        flag[a]++;
    }

    for(i=0;i<m;i++)
    {
        if(flag[i]<p)
            p=flag[i];
    }
    cout<<p<<endl;
}


#include <stdio.h>

int main (void) {
    int num1, value=0, i, j;
    char str1[4];

    scanf("%d", &num1);

    gets(str1);
    for(i=0 ; i<num1; i++ ) {
        gets(str1);
        for(j=0 ; j<3 ; j++) {
            if(str1[j]== '+') {
                value++;
                break;
            }
            else if(str1[j]== '-') {
                value--;
                break;
            }
        }

    }

    printf("%d", value);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,p=INT_MAX;
    cin>>n>>m;
    long long int flag[1000000],a[m];
    memset(flag,0,sizeof(flag));
    for(i=0;i<m;i++)
    {
        cin>>a[i];
        flag[a[i]]++;
    }

    for(i=1;i<=n;i++)
    {
        if(flag[i]<p)
            p=flag[i];
    }
    cout<<p<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int a[1010];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
        int ans,x;
        memset(a,0,sizeof(a));
        for(int i=1;i<=m;i++)
            {
                scanf("%d",&x);
                a[x]++;
            }
                int minn=1010;
            for(int i=1;i<=n;i++)
            {
                //printf("%d ",a[i]);
              ans=min(a[i],minn);
            }
            printf("%d\n",ans);
    return 0;
}
/*#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define LL long long
typedef struct Res//�����ṹ��
{
	int id;
	double x, v;//�ɻ���λ�ú��ٶ�
	bool operator < (const Res &b) const
	{///���¹���ȽϺ������յ�
		if(fabs(x*b.v)<fabs(v*b.x))
			return 1;
		return 0;
	}
}Point;
Point s[100005];
int n, a[100005], b[100005], tre[100005];
int Query(int k)///��״�����ѯǰ׺��
{
	int ans = 0;
	while(k)
	{
		ans += tre[k];
		k -= k &-k;
	}
	return ans;
}
void Update(int k, int val)//��״������½ڵ�
{
	while(k<=n)
	{
		tre[k] += val;
		k += k&-k;
	}
}
int main(void)
{
	int i;
	LL ans;
	double w;
	scanf("%d%lf", &n, &w);
	w += 1e-6;//�������
	for(i=1;i<=n;i++)
	{
		scanf("%lf%lf", &s[i].x, &s[i].v);
		s[i].id = i;//��¼��ǰ������ǵڼ�����
		s[i].v -= w;//��ǰ�ɻ����ٶȼ�ȥ
	}
	sort(s+1, s+n+1);//
	for(i=1;i<=n;i++)
		a[i] = s[i].id;
	for(i=1;i<=n;i++)
		s[i].v += 2*w;
	sort(s+1, s+n+1);
	for(i=1;i<=n;i++)
		b[s[i].id] = i;
	ans = 0;
	for(i=1;i<=n;i++)
	{
		ans += i-1-Query(b[a[i]]);
		Update(b[a[i]], 1);
	}
	printf("%lld\n", ans);
	return 0;
}
#include<bits\stdc++.h>
using namespace std;
int main()
{
	int n,U,a[100000+10];
	scanf("%d%d",&n,&U);
	for(int i=1;i<=n;i++)
        scanf("%d",a+i);
	double ans=-1;
	for(int i=2;i<=n-1;i++)
	{
		if(a[i+1]-a[i-1]>U)
            continue;
		int l=i+1,r=n;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(a[mid]-a[i-1]<=U)
				l=mid+1;
			else r=mid-1;
		}
		ans=max(ans,(1.0*(a[r]-a[i])/(a[r]-a[i-1])));
	}
	if(ans<-0.5)
		printf("-1\n");
	else printf("%.10f\n",ans);
	return 0;
 }*/
/*#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=5e4+5;
struct node{
	int ti;
	int co;
	bool operator<(const node&tt)const{
	return ti<tt.ti;}
}t[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&t[i].ti,&t[i].co);
	}
	sort(t,t+n);
	priority_queue<int ,vector<int >,greater<int> >pq;
	long long  ans=0;
	for(int i=0;i<n;i++)
	{
		int k=t[i].co;
		if(t[i].ti>pq.size())
		{
			ans+=k;
			pq.push(k);
		}
		else
		{
			ans+=k;
			pq.push(k);
			int num=pq.top();
			ans-=num;
			pq.pop();
		}
	}
	printf("%lld\n",ans);
	return 0;
}
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#define maxn 100010
#define mod 998244353
using namespace std;
long long sum[maxn],a[maxn],b[maxn],t[maxn];
long long ans1;
int c[maxn];
int n;

int lowbit(int x)
{
	return x&(-x);
}
void add(int i,int x)
{
	i++;
	if (!i) return;
	for (;i<=n+1;i+=lowbit(i))
        c[i]^=x;
}
int query(int i)
{
	int ans=0;
	i++;
	for (;i;i-=lowbit(i)) ans^=c[i];
	return ans;
}
void calc1(int t)
{
	int sum=1,now=0;
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		int x=((a[i]>>t)&1);
		now^=x;
		if (now==1) ans+=sum;
		else ans+=i-sum,sum++;
	}
	ans1=(ans1+ans*(1ll<<t)%mod)%mod;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
	for (int i=0;i<=20;i++)
        calc1(i);
	printf("%lld\n",ans1);
	return 0;
}*/


#include<bits/stdc++.h>
using namespace std;
int a[1010];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int ans,x;
        memset(a,0,sizeof(a));
        for(int i=1;i<=m;i++)
            {
                scanf("%d",&x);
                a[x]++;
            }
                int minn=1010;
            for(int i=1;i<=n;i++)
            {
                //printf("%d ",a[i]);
              ans=min(a[i],minn);
            }
            printf("%d\n",ans);
    }
    return 0;
}
/*#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define LL long long
typedef struct Res//�����ṹ��
{
	int id;
	double x, v;//�ɻ���λ�ú��ٶ�
	bool operator < (const Res &b) const
	{///���¹���ȽϺ������յ�
		if(fabs(x*b.v)<fabs(v*b.x))
			return 1;
		return 0;
	}
}Point;
Point s[100005];
int n, a[100005], b[100005], tre[100005];
int Query(int k)///��״�����ѯǰ׺��
{
	int ans = 0;
	while(k)
	{
		ans += tre[k];
		k -= k &-k;
	}
	return ans;
}
void Update(int k, int val)//��״������½ڵ�
{
	while(k<=n)
	{
		tre[k] += val;
		k += k&-k;
	}
}
int main(void)
{
	int i;
	LL ans;
	double w;
	scanf("%d%lf", &n, &w);
	w += 1e-6;//�������
	for(i=1;i<=n;i++)
	{
		scanf("%lf%lf", &s[i].x, &s[i].v);
		s[i].id = i;//��¼��ǰ������ǵڼ�����
		s[i].v -= w;//��ǰ�ɻ����ٶȼ�ȥ
	}
	sort(s+1, s+n+1);//
	for(i=1;i<=n;i++)
		a[i] = s[i].id;
	for(i=1;i<=n;i++)
		s[i].v += 2*w;
	sort(s+1, s+n+1);
	for(i=1;i<=n;i++)
		b[s[i].id] = i;
	ans = 0;
	for(i=1;i<=n;i++)
	{
		ans += i-1-Query(b[a[i]]);
		Update(b[a[i]], 1);
	}
	printf("%lld\n", ans);
	return 0;
}
#include<bits\stdc++.h>
using namespace std;
int main()
{
	int n,U,a[100000+10];
	scanf("%d%d",&n,&U);
	for(int i=1;i<=n;i++)
        scanf("%d",a+i);
	double ans=-1;
	for(int i=2;i<=n-1;i++)
	{
		if(a[i+1]-a[i-1]>U)
            continue;
		int l=i+1,r=n;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(a[mid]-a[i-1]<=U)
				l=mid+1;
			else r=mid-1;
		}
		ans=max(ans,(1.0*(a[r]-a[i])/(a[r]-a[i-1])));
	}
	if(ans<-0.5)
		printf("-1\n");
	else printf("%.10f\n",ans);
	return 0;
 }*/
/*#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=5e4+5;
struct node{
	int ti;
	int co;
	bool operator<(const node&tt)const{
	return ti<tt.ti;}
}t[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&t[i].ti,&t[i].co);
	}
	sort(t,t+n);
	priority_queue<int ,vector<int >,greater<int> >pq;
	long long  ans=0;
	for(int i=0;i<n;i++)
	{
		int k=t[i].co;
		if(t[i].ti>pq.size())
		{
			ans+=k;
			pq.push(k);
		}
		else
		{
			ans+=k;
			pq.push(k);
			int num=pq.top();
			ans-=num;
			pq.pop();
		}
	}
	printf("%lld\n",ans);
	return 0;
}
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#define maxn 100010
#define mod 998244353
using namespace std;
long long sum[maxn],a[maxn],b[maxn],t[maxn];
long long ans1;
int c[maxn];
int n;

int lowbit(int x)
{
	return x&(-x);
}
void add(int i,int x)
{
	i++;
	if (!i) return;
	for (;i<=n+1;i+=lowbit(i))
        c[i]^=x;
}
int query(int i)
{
	int ans=0;
	i++;
	for (;i;i-=lowbit(i)) ans^=c[i];
	return ans;
}
void calc1(int t)
{
	int sum=1,now=0;
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		int x=((a[i]>>t)&1);
		now^=x;
		if (now==1) ans+=sum;
		else ans+=i-sum,sum++;
	}
	ans1=(ans1+ans*(1ll<<t)%mod)%mod;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
	for (int i=0;i<=20;i++)
        calc1(i);
	printf("%lld\n",ans1);
	return 0;
}*/


#include<bits/stdc++.h>
using namespace std;
int a[10010];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
        int ans,x;
        memset(a,0,sizeof(a));
        for(int i=1;i<=m;i++)
            {
                scanf("%d",&x);
                a[x]++;
            }
                int minn=10010;
            for(int i=1;i<=n;i++)
            {
              ans=min(a[i],minn);
            }
            printf("%d\n",ans);
    return 0;
}
/*#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define LL long long
typedef struct Res//�����ṹ��
{
	int id;
	double x, v;//�ɻ���λ�ú��ٶ�
	bool operator < (const Res &b) const
	{///���¹���ȽϺ������յ�
		if(fabs(x*b.v)<fabs(v*b.x))
			return 1;
		return 0;
	}
}Point;
Point s[100005];
int n, a[100005], b[100005], tre[100005];
int Query(int k)///��״�����ѯǰ׺��
{
	int ans = 0;
	while(k)
	{
		ans += tre[k];
		k -= k &-k;
	}
	return ans;
}
void Update(int k, int val)//��״������½ڵ�
{
	while(k<=n)
	{
		tre[k] += val;
		k += k&-k;
	}
}
int main(void)
{
	int i;
	LL ans;
	double w;
	scanf("%d%lf", &n, &w);
	w += 1e-6;//�������
	for(i=1;i<=n;i++)
	{
		scanf("%lf%lf", &s[i].x, &s[i].v);
		s[i].id = i;//��¼��ǰ������ǵڼ�����
		s[i].v -= w;//��ǰ�ɻ����ٶȼ�ȥ
	}
	sort(s+1, s+n+1);//
	for(i=1;i<=n;i++)
		a[i] = s[i].id;
	for(i=1;i<=n;i++)
		s[i].v += 2*w;
	sort(s+1, s+n+1);
	for(i=1;i<=n;i++)
		b[s[i].id] = i;
	ans = 0;
	for(i=1;i<=n;i++)
	{
		ans += i-1-Query(b[a[i]]);
		Update(b[a[i]], 1);
	}
	printf("%lld\n", ans);
	return 0;
}
#include<bits\stdc++.h>
using namespace std;
int main()
{
	int n,U,a[100000+10];
	scanf("%d%d",&n,&U);
	for(int i=1;i<=n;i++)
        scanf("%d",a+i);
	double ans=-1;
	for(int i=2;i<=n-1;i++)
	{
		if(a[i+1]-a[i-1]>U)
            continue;
		int l=i+1,r=n;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(a[mid]-a[i-1]<=U)
				l=mid+1;
			else r=mid-1;
		}
		ans=max(ans,(1.0*(a[r]-a[i])/(a[r]-a[i-1])));
	}
	if(ans<-0.5)
		printf("-1\n");
	else printf("%.10f\n",ans);
	return 0;
 }*/
/*#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=5e4+5;
struct node{
	int ti;
	int co;
	bool operator<(const node&tt)const{
	return ti<tt.ti;}
}t[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&t[i].ti,&t[i].co);
	}
	sort(t,t+n);
	priority_queue<int ,vector<int >,greater<int> >pq;
	long long  ans=0;
	for(int i=0;i<n;i++)
	{
		int k=t[i].co;
		if(t[i].ti>pq.size())
		{
			ans+=k;
			pq.push(k);
		}
		else
		{
			ans+=k;
			pq.push(k);
			int num=pq.top();
			ans-=num;
			pq.pop();
		}
	}
	printf("%lld\n",ans);
	return 0;
}
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#define maxn 100010
#define mod 998244353
using namespace std;
long long sum[maxn],a[maxn],b[maxn],t[maxn];
long long ans1;
int c[maxn];
int n;

int lowbit(int x)
{
	return x&(-x);
}
void add(int i,int x)
{
	i++;
	if (!i) return;
	for (;i<=n+1;i+=lowbit(i))
        c[i]^=x;
}
int query(int i)
{
	int ans=0;
	i++;
	for (;i;i-=lowbit(i)) ans^=c[i];
	return ans;
}
void calc1(int t)
{
	int sum=1,now=0;
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		int x=((a[i]>>t)&1);
		now^=x;
		if (now==1) ans+=sum;
		else ans+=i-sum,sum++;
	}
	ans1=(ans1+ans*(1ll<<t)%mod)%mod;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
	for (int i=0;i<=20;i++)
        calc1(i);
	printf("%lld\n",ans1);
	return 0;
}*/


#include<bits/stdc++.h>
using namespace std;
int a[1010];
set<int>s;
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int ans=0;
        for(int i=1;i<=m;i++)
            scanf("%d",&a[i]);
            for(int i=1;i<=m;i++)
            {
              s.insert(a[i]);
              int num=s.size();
              if(num==n)
              {
                  ans++;
                  s.clear();
              }
            }
            printf("%d\n",ans);
    }
    return 0;
}
/*#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define LL long long
typedef struct Res//�����ṹ��
{
	int id;
	double x, v;//�ɻ���λ�ú��ٶ�
	bool operator < (const Res &b) const
	{///���¹���ȽϺ������յ�
		if(fabs(x*b.v)<fabs(v*b.x))
			return 1;
		return 0;
	}
}Point;
Point s[100005];
int n, a[100005], b[100005], tre[100005];
int Query(int k)///��״�����ѯǰ׺��
{
	int ans = 0;
	while(k)
	{
		ans += tre[k];
		k -= k &-k;
	}
	return ans;
}
void Update(int k, int val)//��״������½ڵ�
{
	while(k<=n)
	{
		tre[k] += val;
		k += k&-k;
	}
}
int main(void)
{
	int i;
	LL ans;
	double w;
	scanf("%d%lf", &n, &w);
	w += 1e-6;//�������
	for(i=1;i<=n;i++)
	{
		scanf("%lf%lf", &s[i].x, &s[i].v);
		s[i].id = i;//��¼��ǰ������ǵڼ�����
		s[i].v -= w;//��ǰ�ɻ����ٶȼ�ȥ
	}
	sort(s+1, s+n+1);//
	for(i=1;i<=n;i++)
		a[i] = s[i].id;
	for(i=1;i<=n;i++)
		s[i].v += 2*w;
	sort(s+1, s+n+1);
	for(i=1;i<=n;i++)
		b[s[i].id] = i;
	ans = 0;
	for(i=1;i<=n;i++)
	{
		ans += i-1-Query(b[a[i]]);
		Update(b[a[i]], 1);
	}
	printf("%lld\n", ans);
	return 0;
}
#include<bits\stdc++.h>
using namespace std;
int main()
{
	int n,U,a[100000+10];
	scanf("%d%d",&n,&U);
	for(int i=1;i<=n;i++)
        scanf("%d",a+i);
	double ans=-1;
	for(int i=2;i<=n-1;i++)
	{
		if(a[i+1]-a[i-1]>U)
            continue;
		int l=i+1,r=n;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(a[mid]-a[i-1]<=U)
				l=mid+1;
			else r=mid-1;
		}
		ans=max(ans,(1.0*(a[r]-a[i])/(a[r]-a[i-1])));
	}
	if(ans<-0.5)
		printf("-1\n");
	else printf("%.10f\n",ans);
	return 0;
 }*/
/*#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=5e4+5;
struct node{
	int ti;
	int co;
	bool operator<(const node&tt)const{
	return ti<tt.ti;}
}t[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&t[i].ti,&t[i].co);
	}
	sort(t,t+n);
	priority_queue<int ,vector<int >,greater<int> >pq;
	long long  ans=0;
	for(int i=0;i<n;i++)
	{
		int k=t[i].co;
		if(t[i].ti>pq.size())
		{
			ans+=k;
			pq.push(k);
		}
		else
		{
			ans+=k;
			pq.push(k);
			int num=pq.top();
			ans-=num;
			pq.pop();
		}
	}
	printf("%lld\n",ans);
	return 0;
}
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#define maxn 100010
#define mod 998244353
using namespace std;
long long sum[maxn],a[maxn],b[maxn],t[maxn];
long long ans1;
int c[maxn];
int n;

int lowbit(int x)
{
	return x&(-x);
}
void add(int i,int x)
{
	i++;
	if (!i) return;
	for (;i<=n+1;i+=lowbit(i))
        c[i]^=x;
}
int query(int i)
{
	int ans=0;
	i++;
	for (;i;i-=lowbit(i)) ans^=c[i];
	return ans;
}
void calc1(int t)
{
	int sum=1,now=0;
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		int x=((a[i]>>t)&1);
		now^=x;
		if (now==1) ans+=sum;
		else ans+=i-sum,sum++;
	}
	ans1=(ans1+ans*(1ll<<t)%mod)%mod;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
	for (int i=0;i<=20;i++)
        calc1(i);
	printf("%lld\n",ans1);
	return 0;
}*/


#include<bits/stdc++.h>
using namespace std;
int a[10010];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
        int ans,x;
        memset(a,0,sizeof(a));
        for(int i=1;i<=m;i++)
            {
                scanf("%d",&x);
                a[x]++;
            }
                int minn=10010;
            for(int i=1;i<=n;i++)
            {
              minn=min(a[i],minn);
            }
            printf("%d\n",minn);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=0, k, i;
   cin>>n>>m;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=0; i<m; i++)
      if( v[i]==n ) x++;

      cout << x;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=1, i, j=0, k;
   cin>>n>>m;
   int a[n];
   a[0]=0;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=0; i<m-1; i++)
   {
       if(v[i]==v[i+1] || v[i]==v[i+1]-1) ;
       else {cout<<0; return 0;}
   }
   for(i=0; i<m; i++)
   {
       if(v[i]==x) a[j]+=1;
       else if(v[i]==x+1)
       {
           x++;
           j++;
           a[j]=1;
       }
   }
   k=a[0];
   for(i=0; i<j; i++)
   {
       if(a[i+1]<k) k=a[i+1];
   }
   cout<<k;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=1, i, j=0, k;
   cin>>n>>m;
   int a[m];
   a[j]=0;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=0; i<m; i++)
   {
       if(v[i]==v[i+1] || v[i]==v[i+1]-1) continue;
       else {cout<<0; return 0;}
   }
   for(i=0; i<m; i++)
   {
       if(v[i]==x) a[j]+=1;
       else if(v[i]==x+1)
       {
           x++;
           j++;
           a[j]=1;
       }
   }
   k=a[0];
   for(i=0; i<j; i++)
   {
       if(a[i+1]<k) k=a[i+1];
   }
   cout<<k;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=0, k, i;
   cin>>n>>m;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=0; i<m; i++)
    {
       if(v[i]!=v[i+1] || v[i]!=v[i+1]-1)break;
       if(v[i]==n)x++;
    }
    cout << x;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=1, i, j=0, k;
   cin>>n>>m;
   int a[n];
   a[0]=0;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   if(v[m-1]!=n)
   {
       cout<<0;
       return 0;
   }

   for(i=0; i<m-1; i++)
   {
       if(v[i]==v[i+1] || v[i]==v[i+1]-1) ;
       else {cout<<0; return 0;}
   }
   for(i=0; i<m; i++)
   {
       if(v[i]==x) a[j]+=1;
       else if(v[i]==x+1)
       {
           x++;
           j++;
           a[j]=1;
       }
   }
   k=a[0];
   for(i=0; i<j; i++)
   {
       if(a[i+1]<k) k=a[i+1];
   }
   cout<<k;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=1, i, j=0, k;
   cin>>n>>m;
   int a[n];
   a[0]=0;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=0; i<m; i++)
   {
       if(v[i]==v[i+1] || v[i]==v[i+1]-1) continue;
       else {cout<<0; return 0;}
   }
   for(i=0; i<m; i++)
   {
       if(v[i]==x) a[j]+=1;
       else if(v[i]==x+1)
       {
           x++;
           j++;
           a[j]=1;
       }
   }
   k=a[0];
   for(i=0; i<j; i++)
   {
       if(a[i+1]<k) k=a[i+1];
   }
   cout<<k;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=1, i, j=0, k;
   cin>>n>>m;
   int a[m];
   a[j]=0;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=0; i<n; i++)
   {
       if(v[i]==v[i+1] || v[i]==v[i+1]-1) continue;
       else {cout<<0; return 0;}
   }
   for(i=0; i<m; i++)
   {
       if(v[i]==x) a[j]+=1;
       else if(v[i]==x+1)
       {
           x++;
           j++;
           a[j]=1;
       }
   }
   k=a[0];
   for(i=0; i<j; i++)
   {
       if(a[i+1]<k) k=a[i+1];
   }
   cout<<k;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=0, k, i;
   cin>>n>>m;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=0; i<m; i++)
    {
       if(v[i]==v[i+1] || v[i]==v[i+1]-1)break;
       if(v[i]==n)x++;
    }
    cout << x;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=0, k, i;
   cin>>n>>m;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=2; i<m; i++)
      if( v[i]==3 ) x++;

      cout << x;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   vector <int> v;
   int n, m, x=1, i, j=0, k;
   cin>>n>>m;
   int a[m];
   a[j]=0;

   for(i=0; i<m; i++)
   {
       cin >> k;
       v.push_back(k);
   }
   sort( v.begin(), v.end() );

   for(i=0; i<n; i++)
   {
       if(v[i]==v[i+1] || v[i]==v[i+1]-1) continue;
       else {cout<<0; return 0;}
   }
   for(i=0; i<m; i++)
   {
       if(v[i]==x) a[j]+=1;
       else if(v[i]==x+1)
       {
           x++;
           j++;
           a[j]=1;
       }
   }
   k=a[0];
   for(i=0; i<j; i++)
   {
       if(a[i+1]>k) k=a[i+1];
   }
   cout<<k;
  return 0;
}


//#define NOSTDCPP
//#define Cpp11
//#define Linux_System
#ifndef NOSTDCPP

#include <bits/stdc++.h>

#else

#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstring>
#include <cstdio>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#endif

# ifdef Linux_System
# define getchar getchar_unlocked
# define putchar putchar_unlocked
# endif

# define RESET(_) memset(_, 0, sizeof(_))
# define RESET_(_, val) memset(_, val, sizeof(_))
# define fi first
# define se second
# define pb push_back
# define midf(x, y) ((x + y) >> 1)
# define DXA(_) ((_ << 1))
# define DXB(_) ((_ << 1) | 1)

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef set <int> si;
typedef pair <int, int> pii;
typedef long double ld;

const int MOD = 1e9 + 7;
const int maxn = 300009;
const int maxm = 300009;
const double pi = acos(-1.0);
const double eps = 1e-6;

ll myrand(ll mod){return ((ll)rand() << 32 ^ (ll)rand() << 16 ^ rand()) % mod;}

template <class T>
inline bool scan_d(T & ret)
{
	char c;
	int sgn;
	if(c = getchar(), c == EOF)return false;
	while(c != '-' && (c < '0' || c > '9'))c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while(c = getchar(), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return true;
}
#ifdef Cpp11
template <class T, class ... Args>
inline bool scan_d(T & ret, Args & ... args)
{
	scan_d(ret);
	scan_d(args...);
}
#endif
inline bool scan_ch(char &ch)
{
	if(ch = getchar(), ch == EOF)return false;
	while(ch == ' ' || ch == '\n')ch = getchar();
	return true;
}

inline void out_number(ll x)
{
	if(x < 0)
	{
		putchar('-');
		out_number(- x);
		return ;
	}
	if(x > 9)out_number(x / 10);
	putchar(x % 10 + '0');
}

int data[maxn];

int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int ans = 0, n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
		cin >> data[i];
	for(int nn = 1; ; nn ++)
	{
		for(int i = 1; i <= m; i ++)
		{
			if(data[i] == n - nn + 1)
			{
				data[(i + m - 1) % m] --;
				data[i] --;
				data[(i + 1) % m] --;
				ans ++;
			}
		}
		int two0 = 0;
		for(int i = 1; i <= m; i ++)
			if(data[i] == 0)
				two0 ++;
		if(two0 >= n - 1)break;
	}
	cout << ans << endl;
	return 0;
}


//#define NOSTDCPP
//#define Cpp11
//#define Linux_System
#ifndef NOSTDCPP

#include <bits/stdc++.h>

#else

#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstring>
#include <cstdio>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#endif

# ifdef Linux_System
# define getchar getchar_unlocked
# define putchar putchar_unlocked
# endif

# define RESET(_) memset(_, 0, sizeof(_))
# define RESET_(_, val) memset(_, val, sizeof(_))
# define fi first
# define se second
# define pb push_back
# define midf(x, y) ((x + y) >> 1)
# define DXA(_) ((_ << 1))
# define DXB(_) ((_ << 1) | 1)

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef set <int> si;
typedef pair <int, int> pii;
typedef long double ld;

const int MOD = 1e9 + 7;
const int maxn = 300009;
const int maxm = 300009;
const double pi = acos(-1.0);
const double eps = 1e-6;

ll myrand(ll mod){return ((ll)rand() << 32 ^ (ll)rand() << 16 ^ rand()) % mod;}

template <class T>
inline bool scan_d(T & ret)
{
	char c;
	int sgn;
	if(c = getchar(), c == EOF)return false;
	while(c != '-' && (c < '0' || c > '9'))c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while(c = getchar(), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return true;
}
#ifdef Cpp11
template <class T, class ... Args>
inline bool scan_d(T & ret, Args & ... args)
{
	scan_d(ret);
	scan_d(args...);
}
#endif
inline bool scan_ch(char &ch)
{
	if(ch = getchar(), ch == EOF)return false;
	while(ch == ' ' || ch == '\n')ch = getchar();
	return true;
}

inline void out_number(ll x)
{
	if(x < 0)
	{
		putchar('-');
		out_number(- x);
		return ;
	}
	if(x > 9)out_number(x / 10);
	putchar(x % 10 + '0');
}

int data[maxn];

int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int ans = 0, n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
		cin >> data[i];
	for(int i = 1; i <= m; i ++)
		if(data[i] == n)
		{
			ans ++;
		}
	cout << ans << endl;
	return 0;
}


//#define NOSTDCPP
//#define Cpp11
//#define Linux_System
#ifndef NOSTDCPP

#include <bits/stdc++.h>

#else

#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstring>
#include <cstdio>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#endif

# ifdef Linux_System
# define getchar getchar_unlocked
# define putchar putchar_unlocked
# endif

# define RESET(_) memset(_, 0, sizeof(_))
# define RESET_(_, val) memset(_, val, sizeof(_))
# define fi first
# define se second
# define pb push_back
# define midf(x, y) ((x + y) >> 1)
# define DXA(_) ((_ << 1))
# define DXB(_) ((_ << 1) | 1)

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef set <int> si;
typedef pair <int, int> pii;
typedef long double ld;

const int MOD = 1e9 + 7;
const int maxn = 300009;
const int maxm = 300009;
const double pi = acos(-1.0);
const double eps = 1e-6;

ll myrand(ll mod){return ((ll)rand() << 32 ^ (ll)rand() << 16 ^ rand()) % mod;}

template <class T>
inline bool scan_d(T & ret)
{
	char c;
	int sgn;
	if(c = getchar(), c == EOF)return false;
	while(c != '-' && (c < '0' || c > '9'))c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while(c = getchar(), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return true;
}
#ifdef Cpp11
template <class T, class ... Args>
inline bool scan_d(T & ret, Args & ... args)
{
	scan_d(ret);
	scan_d(args...);
}
#endif
inline bool scan_ch(char &ch)
{
	if(ch = getchar(), ch == EOF)return false;
	while(ch == ' ' || ch == '\n')ch = getchar();
	return true;
}

inline void out_number(ll x)
{
	if(x < 0)
	{
		putchar('-');
		out_number(- x);
		return ;
	}
	if(x > 9)out_number(x / 10);
	putchar(x % 10 + '0');
}

int data[maxn];

int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int ans = 0;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
		cin >> data[i];
	for(int i = 1; i <= m; i ++)
		if(data[i] == n)
		{
			ans ++;
		}
	cout << ans << endl;
	return 0;
}


//#define NOSTDCPP
//#define Cpp11
//#define Linux_System
#ifndef NOSTDCPP

#include <bits/stdc++.h>

#else

#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstring>
#include <cstdio>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#endif

# ifdef Linux_System
# define getchar getchar_unlocked
# define putchar putchar_unlocked
# endif

# define RESET(_) memset(_, 0, sizeof(_))
# define RESET_(_, val) memset(_, val, sizeof(_))
# define fi first
# define se second
# define pb push_back
# define midf(x, y) ((x + y) >> 1)
# define DXA(_) ((_ << 1))
# define DXB(_) ((_ << 1) | 1)

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef set <int> si;
typedef pair <int, int> pii;
typedef long double ld;

const int MOD = 1e9 + 7;
const int maxn = 300009;
const int maxm = 300009;
const double pi = acos(-1.0);
const double eps = 1e-6;

ll myrand(ll mod){return ((ll)rand() << 32 ^ (ll)rand() << 16 ^ rand()) % mod;}

template <class T>
inline bool scan_d(T & ret)
{
	char c;
	int sgn;
	if(c = getchar(), c == EOF)return false;
	while(c != '-' && (c < '0' || c > '9'))c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while(c = getchar(), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return true;
}
#ifdef Cpp11
template <class T, class ... Args>
inline bool scan_d(T & ret, Args & ... args)
{
	scan_d(ret);
	scan_d(args...);
}
#endif
inline bool scan_ch(char &ch)
{
	if(ch = getchar(), ch == EOF)return false;
	while(ch == ' ' || ch == '\n')ch = getchar();
	return true;
}

inline void out_number(ll x)
{
	if(x < 0)
	{
		putchar('-');
		out_number(- x);
		return ;
	}
	if(x > 9)out_number(x / 10);
	putchar(x % 10 + '0');
}

int data[maxn];

int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int ans = 0, n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
		cin >> data[i];
	for(int i = 1; i <= m; i ++)
		if(data[i] == 1)
		{
			ans ++;
		}
	cout << ans - 1 << endl;
	return 0;
}


//#define NOSTDCPP
//#define Cpp11
//#define Linux_System
#ifndef NOSTDCPP

#include <bits/stdc++.h>

#else

#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstring>
#include <cstdio>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#endif

# ifdef Linux_System
# define getchar getchar_unlocked
# define putchar putchar_unlocked
# endif

# define RESET(_) memset(_, 0, sizeof(_))
# define RESET_(_, val) memset(_, val, sizeof(_))
# define fi first
# define se second
# define pb push_back
# define midf(x, y) ((x + y) >> 1)
# define DXA(_) ((_ << 1))
# define DXB(_) ((_ << 1) | 1)

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef set <int> si;
typedef pair <int, int> pii;
typedef long double ld;

const int MOD = 1e9 + 7;
const int maxn = 300009;
const int maxm = 300009;
const double pi = acos(-1.0);
const double eps = 1e-6;

ll myrand(ll mod){return ((ll)rand() << 32 ^ (ll)rand() << 16 ^ rand()) % mod;}

template <class T>
inline bool scan_d(T & ret)
{
	char c;
	int sgn;
	if(c = getchar(), c == EOF)return false;
	while(c != '-' && (c < '0' || c > '9'))c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while(c = getchar(), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return true;
}
#ifdef Cpp11
template <class T, class ... Args>
inline bool scan_d(T & ret, Args & ... args)
{
	scan_d(ret);
	scan_d(args...);
}
#endif
inline bool scan_ch(char &ch)
{
	if(ch = getchar(), ch == EOF)return false;
	while(ch == ' ' || ch == '\n')ch = getchar();
	return true;
}

inline void out_number(ll x)
{
	if(x < 0)
	{
		putchar('-');
		out_number(- x);
		return ;
	}
	if(x > 9)out_number(x / 10);
	putchar(x % 10 + '0');
}

int data[maxn];

int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int ans = 1e10, n, m, xx;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
		cin >> xx, data[xx] ++;
	for(int i = 1; i <= n; i ++)ans = min(ans, data[i]);
	cout << ans << endl;
	return 0;
}


//#define NOSTDCPP
//#define Cpp11
//#define Linux_System
#ifndef NOSTDCPP

#include <bits/stdc++.h>

#else

#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstring>
#include <cstdio>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#endif

# ifdef Linux_System
# define getchar getchar_unlocked
# define putchar putchar_unlocked
# endif

# define RESET(_) memset(_, 0, sizeof(_))
# define RESET_(_, val) memset(_, val, sizeof(_))
# define fi first
# define se second
# define pb push_back
# define midf(x, y) ((x + y) >> 1)
# define DXA(_) ((_ << 1))
# define DXB(_) ((_ << 1) | 1)

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef set <int> si;
typedef pair <int, int> pii;
typedef long double ld;

const int MOD = 1e9 + 7;
const int maxn = 300009;
const int maxm = 300009;
const double pi = acos(-1.0);
const double eps = 1e-6;

ll myrand(ll mod){return ((ll)rand() << 32 ^ (ll)rand() << 16 ^ rand()) % mod;}

template <class T>
inline bool scan_d(T & ret)
{
	char c;
	int sgn;
	if(c = getchar(), c == EOF)return false;
	while(c != '-' && (c < '0' || c > '9'))c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while(c = getchar(), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return true;
}
#ifdef Cpp11
template <class T, class ... Args>
inline bool scan_d(T & ret, Args & ... args)
{
	scan_d(ret);
	scan_d(args...);
}
#endif
inline bool scan_ch(char &ch)
{
	if(ch = getchar(), ch == EOF)return false;
	while(ch == ' ' || ch == '\n')ch = getchar();
	return true;
}

inline void out_number(ll x)
{
	if(x < 0)
	{
		putchar('-');
		out_number(- x);
		return ;
	}
	if(x > 9)out_number(x / 10);
	putchar(x % 10 + '0');
}

int data[maxn];

int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int ans = 0, n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
		cin >> data[i];
	for(int nn = 1; ; nn ++)
	{
		for(int i = 1; i <= m; i ++)
		{
			if(data[i] == n)
			{
				data[(i + m - 1) % m] --;
				data[i] --;
				data[(i + 1) % m] --;
				ans ++;
			}
		}
		n --;
		int two0 = 0;
		for(int i = 1; i <= m; i ++)
			if(data[i] == 0)
				two0 ++;
		if(two0 >= 2)break;
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

void Never_give_up()

{
   int n,m; cin>>n>>m; int cnt=0;
   for(int i=1;i<=m;++i)
        { int tmp; cin>>tmp;
        }
if(n>=m) cout<<0;
else cout<<m/n-1;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0);

int tc=1;
//cin >> tc;
for (int iTest = 0; iTest <tc; ++iTest)
 {
Never_give_up();
 }

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

void Never_give_up()

{
   int n,m; cin>>n>>m;
   for(int i=1;i<=m;++i) { int tmp; cin>>tmp;}
   cout<<(m/n)-1;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0);

int tc=1;
//cin >> tc;
for (int iTest = 0; iTest <tc; ++iTest)
 {
Never_give_up();
 }

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

void Never_give_up()

{
   int n,m; cin>>n>>m; int cnt=0;
   for(int i=1;i<=m;++i)
        { int tmp; cin>>tmp;
        }
if(n<=m) cout<<0;
else cout<<m/n-1;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0);

int tc=1;
//cin >> tc;
for (int iTest = 0; iTest <tc; ++iTest)
 {
Never_give_up();
 }

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

int a[2000],t;
void Never_give_up()

{
  int n,m; cin>>n>>m;
  for(int i=0;i<m;++i)
  {
      cin>>t; a[t]++;
  }
  //for(int i=0;i<=n;++i) cout<<a[i]<<' ';
  sort(a+1,a+n+1); cout<<a[1];
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0);

int tc=1;
//cin >> tc;
for (int iTest = 0; iTest <tc; ++iTest)
 {
Never_give_up();
 }

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

void Never_give_up()

{
    map<int,int>mp;
   int n,m; cin>>n>>m; int ans=INT_MAX;
   for(int i=1;i<=m;++i)
        { int tmp; cin>>tmp; mp[tmp]++;
        }
    for(auto e : mp)

        if(e.second < ans) ans = e.second;

    if(ans==1) ans =0;
    cout<<ans;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0);

int tc=1;
//cin >> tc;
for (int iTest = 0; iTest <tc; ++iTest)
 {
Never_give_up();
 }

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

void Never_give_up()

{
   int n,m; cin>>n>>m; int cnt=0;
   for(int i=1;i<=m;++i)
        { int tmp; cin>>tmp;
        }
if(n>=m) cout<<0;
else {
    int res = m/n; if(res &1) cout<<res-1;
    else cout<<res;
}
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0);

int tc=1;
//cin >> tc;
for (int iTest = 0; iTest <tc; ++iTest)
 {
Never_give_up();
 }

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

void Never_give_up()

{
    map<int,int>mp;
   int n,m; cin>>n>>m; int ans=INT_MAX;
   for(int i=1;i<=m;++i)
        { int tmp; cin>>tmp; mp[tmp]++;
        }
    for(auto e : mp)
        if(e.second < ans) ans = e.second;
    cout<<ans;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0);

int tc=1;
//cin >> tc;
for (int iTest = 0; iTest <tc; ++iTest)
 {
Never_give_up();
 }

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N = 2e5+5 ;
//😁😁😁😁😁😁😁😁😁😁😁

void Never_give_up()

{
    map<int,int>mp;
   int n,m; cin>>n>>m; int ans=INT_MAX;
   for(int i=1;i<=m;++i)
        { int tmp; cin>>tmp; mp[tmp]++;
        }
    for(auto e : mp)

        if(e.second < ans) ans = e.second;

    if(ans==1) ans ==0;
    cout<<ans;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0);

int tc=1;
//cin >> tc;
for (int iTest = 0; iTest <tc; ++iTest)
 {
Never_give_up();
 }

 return 0;
}


#include <cstdio>
const int S=1003;
int m,n,a[S],t;
int main()
{
	scanf("%d%d",&m,&n);
	for (int i=1,x;i<=n;i++)
		scanf("%d",&x),a[x]++;
	t=n;
	for (int i=1;i<=m;i++)
		if (a[i]<t) t=a[i];
	printf("%d",t);
	return 0;
}


#include <cstdio>
const int S=1003;
int m,n,a[S],t=1;
int main()
{
	scanf("%d%d",&m,&n);
	for (int i=1,x;i<=n;i++)
		scanf("%d",&x),a[x]++;
	for (int i=2;i<=m;i++)
		if (a[i]>a[t]) t=i;
	printf("%d",t);
	return 0;
}


#include <cstdio>
const int S=1003;
int m,n,a[S],t=S;
int main()
{
	scanf("%d%d",&m,&n);
	for (int i=1,x;i<=n;i++)
		scanf("%d",&x),a[x]++;
	for (int i=2;i<=m;i++)
		if (a[i]<t) t=a[i];
	printf("%d",t);
	return 0;
}


#include <cstdio>
const int S=1003;
int m,n,a[S],t;
int main()
{
	scanf("%d%d",&m,&n);
	for (int i=1,x;i<=n;i++)
		scanf("%d",&x),a[x]++;
	t=m;
	for (int i=1;i<=m;i++)
		if (a[i]<t) t=a[i];
	printf("%d",t);
	return 0;
}


#include <cstdio>
const int S=1003;
int m,n,a[S],t=S-3;
int main()
{
	scanf("%d%d",&m,&n);
	for (int i=1,x;i<=n;i++)
		scanf("%d",&x),a[x]++;
	for (int i=2;i<=m;i++)
		if (a[i]<t) t=a[i];
	printf("%d",t);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,k=INT_MAX;
    cin>>n>>m;
  //int a[10001];
  int b[n+1]={0};
 // memset(b, 0, sizeof(b));
    for(int i=0;i<m;i++)
    {
        int p;
      cin>>p;
      b[p]++;
    }
   for(int i=1;i<=n;i++)
   {
    if(k>=b[i])
    {
        k=b[i];
    }
   }
   cout<<k;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
void countFreq(int arr[], int n)
{
    unordered_map<int, int> mp;
     int k=INT_MAX;
    for (int i = 0; i < n; i++)
        mp[arr[i]]++;
    for (auto x : mp)
    {
        if(x.second<k)
        {
            k=x.second;
        }
    }
    cout<<k<<endl;
}
int main()
{
    int n,m,count=0;
    cin>>n>>m;
  int a[m];
    for(int i=0;i<m;i++)
    {
      cin>>a[i];
    }
    countFreq(a,m);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
void countFreq(int arr[], int n)
{
    unordered_map<int, int> mp;
     int k=INT_MAX;
    for (int i = 0; i < n; i++)
        mp[arr[i]]++;
    for (auto x : mp)
    {
        if(x.second<=k)
        {
            k=x.second;
        }
    }
    cout<<k<<endl;
}
int main()
{
    int n,m,count=0;
    cin>>n>>m;
  int a[m];
    for(int i=0;i<m;i++)
    {
      cin>>a[i];
    }
    countFreq(a,m);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m, aux, points;
    vector<int>freq;

    scanf("%d %d", &n, &m);
    points = m/n;

    for(int i = 0; i < n; i++) {
        freq.push_back(0);
    }
    for(int i = 0; i < m; i++) {
        scanf("%d", &aux);
        freq[aux-1]++;
    }
    for(int i = 0; i < n; i++) {
        if(freq[i] < points) {
            points = freq[i];
        }
    }
    printf("%d\n", points);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m, aux, points;

    scanf("%d %d", &n, &m);
    int freq[n];
    points = m/n;

    for(int i = 0; i < n; i++) {
        freq[i] = 0;
    }
    for(int i = 0; i < m; i++) {
        scanf("%d", &aux);
        freq[aux-1]++;
    }
    for(int i = 0; i < n; i++) {
        if(freq[i] < points) {
            points = freq[i];
        }
    }
    printf("%d\n", points);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m, aux, points;
    vector<int> c, freq;

    scanf("%d %d", &n, &m);
    points = m/n;

    for(int i = 0; i < m; i++) {
        scanf("%d", &aux);
        c.push_back(aux);
    }
    for(int i = 0; i < n; i++) {
        freq.push_back(0);
    }
    for(int i = 0; i < m; i++) {
        freq[c[i]-1]++;
    }
    for(int i = 0; i < n; i++) {
        if(freq[i] < points) {
            points = freq[i];
        }
    }
    printf("%d\n", points);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m, aux;
    vector<int> c;
    map<int, int> mymap;
    int points = 10000;
    scanf("%d %d", &n, &m);
    for(int i = 0; i < m; i++) {
        scanf("%d", &aux);
        c.push_back(aux);
    }

    for(int i = 1; i <= n; i++) {
        mymap[i] = 0;
    }

    for(int i = 0; i < m; i++) {
        mymap[c[i]]++;
    }

    for(int i = 1; i <= n; i++) {
        if(mymap[i] < points) {
            points = mymap[i];
        }
    }

     printf("%d\n", points);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int col[1005],level[1005],vis[1005][1005];
int main()
{
        int n,m,point=0;
        cin>>n>>m;
        memset(col,0,sizeof(col));
        for(int i=1;i<=m;i++)
        {
                int x;
                cin>>x;
                col[x]++;
                level[i]=col[x];
                vis[level[i]][x]=1;
        }
        bool ok=true;
        int re=0;
        sort(level+1,level+n+1);
        for(int i=1;i<=1003;i++)
                for(int j=1;j<=n;j++)
                {
                        if(vis[i][j]==0)
                        {
                                ok=false;
                                re=point;
                                cout<<re;
                                return 0;
                        }
                        if(j==n&&vis[i][j]==1)
                                point++;
                }
        if(ok)
                cout<<point;
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
int col[1005],level[1005],vis[1005][1005];
int main()
{
        int n,m,point=0;
        cin>>n>>m;
        memset(col,0,sizeof(col));
        for(int i=1;i<=m;i++)
        {
                int x;
                cin>>x;
                col[x]++;
                level[i]=col[x];
                vis[level[i]][x]=1;
        }
        sort(level+1,level+n+1);
        bool ok=true;
        for(int i=1;i<=level[n];i++)
                for(int j=1;j<=n;j++)
                {
                        if(vis[i][j]==0)
                        {
                                ok=false;
                                break;
                        }
                        if(j==n&&vis[i][j]==1)
                                point++;
                }
        if(ok)
                cout<<point;
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
int col[1005],level[1005],vis[1005][1005];
int main()
{
        int n,m,point=0;
        cin>>n>>m;
        memset(col,0,sizeof(col));
        for(int i=1;i<=m;i++)
        {
                int x;
                cin>>x;
                col[x]++;
                level[i]=col[x];
                vis[level[i]][x]=1;
        }
        sort(level+1,level+n+1);
        for(int i=1;i<=1003;i++)
                for(int j=1;j<=n;j++)
                        if(j==n&&vis[i][j]==1)
                                point++;
        cout<<point;
        return 0;
}


#include <bits/stdc++.h>

#define fr first
#define sc second
typedef long long ll;
using namespace std;

ll const M=1e5+10,N=1e8+10,pi=acos(-1);
int n,m,x,ans,cnt;
map<int,int> a;
int main(){
    cin>>n>>m;
    ans=cnt=0;
    for(int i=0;i<m;i++){
        cin>>x;
        if(!a[x]){
            a[x]++;
            cnt++;
        }
        if(cnt==n){
            for(int j=1;j<=n;j++)a[j]--;
            cnt--;
            ans++;
        }
    }
    cout<<ans;
}
/*int mx,k;
int n,a[M],b[M];
int main()
{
//    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=n-1;i>=0;i--){
        b[i]=1;
        for(int j=i;j<n;j++){
            if(a[j]==a[i]+1){
                     b[i]+=b[j];
            }
        }
    }
    for(int i=0;i<n;i++){
            if(b[i]>mx){mx=b[i],k=i;}
    }
    int kk=n;
    for(int i=k+1,y=1;i<n;i++){
        if(a[i]==a[k]+y)y++;
        if(y==mx){kk=i;break;}
    }
    a[n]=1e9;
    cout<<n-mx<<endl;
    for(int i=a[k]-1;i>0;i--){
        printf("%d 0\n",i);
    }
    for(int i=a[kk]+1;i<=n;i++){
        printf("%d 1\n",i);
    }
}*/


#include <bits/stdc++.h>

#define fr first
#define sc second
typedef long long ll;
using namespace std;

ll const M=1e5+10,N=1e8+10,pi=acos(-1);
int n,m,x,ans,cnt;
map<int,int> a;
int main(){
    cin>>n>>m;
    ans=cnt=0;
    for(int i=0;i<m;i++){
        cin>>x;
        if(!a[x]){
            a[x]++;
            cnt++;
        }
        if(cnt==n){
            for(int j=1;j<=n;j++)a[j]--;
            cnt=0;
            ans++;
        }
    }
    cout<<ans;
}
/*int mx,k;
int n,a[M],b[M];
int main()
{
//    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=n-1;i>=0;i--){
        b[i]=1;
        for(int j=i;j<n;j++){
            if(a[j]==a[i]+1){
                     b[i]+=b[j];
            }
        }
    }
    for(int i=0;i<n;i++){
            if(b[i]>mx){mx=b[i],k=i;}
    }
    int kk=n;
    for(int i=k+1,y=1;i<n;i++){
        if(a[i]==a[k]+y)y++;
        if(y==mx){kk=i;break;}
    }
    a[n]=1e9;
    cout<<n-mx<<endl;
    for(int i=a[k]-1;i>0;i--){
        printf("%d 0\n",i);
    }
    for(int i=a[kk]+1;i<=n;i++){
        printf("%d 1\n",i);
    }
}*/


#include <bits/stdc++.h>

#define fr first
#define sc second
typedef long long ll;
using namespace std;

ll const M=1e5+10,N=1e8+10,pi=acos(-1);
int n,m,x,ans,cnt;
map<int,int> a;
int main(){
    cin>>n>>m;
    ans=cnt=0;
    for(int i=0;i<m;i++){
        cin>>x;
        if(!a[x]){
            a[x]++;
            cnt++;
        }
        if(cnt==n){
            for(int j=1;j<=n;j++){a[j]--;
            if(!a[j])cnt--;
            }
            ans++;
        }
    }
    cout<<ans;
}
/*int mx,k;
int n,a[M],b[M];
int main()
{
//    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=n-1;i>=0;i--){
        b[i]=1;
        for(int j=i;j<n;j++){
            if(a[j]==a[i]+1){
                     b[i]+=b[j];
            }
        }
    }
    for(int i=0;i<n;i++){
            if(b[i]>mx){mx=b[i],k=i;}
    }
    int kk=n;
    for(int i=k+1,y=1;i<n;i++){
        if(a[i]==a[k]+y)y++;
        if(y==mx){kk=i;break;}
    }
    a[n]=1e9;
    cout<<n-mx<<endl;
    for(int i=a[k]-1;i>0;i--){
        printf("%d 0\n",i);
    }
    for(int i=a[kk]+1;i<=n;i++){
        printf("%d 1\n",i);
    }
}*/


#include <bits/stdc++.h>

#define fr first
#define sc second
typedef long long ll;
using namespace std;

ll const M=1e5+10,N=1e8+10,pi=acos(-1);
int n,m,x,ans,cnt;
int a[M];
int main(){
    cin>>n>>m;
    ans=cnt=0;
    for(int i=0;i<m;i++){
        cin>>x;
        if(!a[x])cnt++;
        a[x]++;
        if(cnt==n){
            for(int j=1;j<=n;j++){
                a[j]--;
                if(!a[j])cnt--;
            }
            ans++;
        }
    }
    cout<<ans;
}
/*int mx,k;
int n,a[M],b[M];
int main()
{
//    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=n-1;i>=0;i--){
        b[i]=1;
        for(int j=i;j<n;j++){
            if(a[j]==a[i]+1){
                     b[i]+=b[j];
            }
        }
    }
    for(int i=0;i<n;i++){
            if(b[i]>mx){mx=b[i],k=i;}
    }
    int kk=n;
    for(int i=k+1,y=1;i<n;i++){
        if(a[i]==a[k]+y)y++;
        if(y==mx){kk=i;break;}
    }
    a[n]=1e9;
    cout<<n-mx<<endl;
    for(int i=a[k]-1;i>0;i--){
        printf("%d 0\n",i);
    }
    for(int i=a[kk]+1;i<=n;i++){
        printf("%d 1\n",i);
    }
}*/


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

int main()
{
    int n,m;
    cin>>n>>m;
    map<int , int >m1;
    int cnt=0;
    for(int i=0; i<m;i++)
    {
        int temp,c=0;
        cin>>temp;
        m1[temp]++;
        for(int i=1;i<=n;i++)
        {
            if(m1[i]==0) break;
            else c++;

        }
        if(c==n){
            cnt++;
            for(int i=1;i<=n;i++)  m1[i]--;

        }
    }
    cout<< cnt<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    map<int,int>m1;
    int ans=INT_MAX;
    for(int i=0;i<m;i++){
        int t;cin>>t;
        m1[t]++;
    }

    if(m1.size()==n)
        for(auto it=m1.begin();it!=m1.end();it++)ans=min(ans,it->second);
    else ans=0;
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    map<int , int >m1;
    for(int i=0; i<m;i++)
    {
        int temp,c=0;
        cin>>temp;
        if(m1[temp]>=1) m1[temp]--;
        else m1[temp]++;
    }
    int left=0;
    for(int i=1;i<=n;i++)
    {
        if(m1[i]) left+=m1[i];
    }
    int ans= m- left;
    cout<< ans/n<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    map<int,int>m1;
    int ans=INT_MAX;
    for(int i=0;i<m;i++){
        int t;cin>>;
        m1[t]++;
    }

    if(m1.size()==n)
        for(auto it=m1.begin();it!=m1.end();it++)ans=min(ans,it->second);
    else ans=0;
    cout<<ans<<endl;
    return 0;
}


// #include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n,m; //n is the size, m is the num squares
    cin>>n>>m;
    int points = 0;
    int column;
    int current[n];
    for (int i = 0; i < n; ++i) {
        current[i] = 0;
    }
    while(cin>>column) {
        current[column-1]++;
        // bool isGood = true;
        // for(int i = 0; i<n;i++){
        //     if(current[i] <= points){
        //         isGood = false;
        //         break;
        //     }
        // }
        // if(isGood){
        //     points++;
        // }
    }

    cout<<min_element(current[0],current[n]);
    // cout<<points;

    return 0;
}


// #include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n,m; //n is the size, m is the num squares
    cin>>n>>m;
    int points = 0;
    int column;
    int current[n];
    for (int i = 0; i < n; ++i) {
        current[i] = 0;
    }
    while(cin>>column) {
        current[column-1]++;
        // bool isGood = true;
        // for(int i = 0; i<n;i++){
        //     if(current[i] <= points){
        //         isGood = false;
        //         break;
        //     }
        // }
        // if(isGood){
        //     points++;
        // }
    }

    cout<<*min_element(current,current+n);
    // cout<<points;

    return 0;
}


// #include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <string.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n,m; //n is the size, m is the num squares
    cin>>n>>m;
    int points = 0;
    int column;
    int current[n];
    for (int i = 0; i < n; ++i) {
        current[i] = 0;
    }
    while(cin>>column) {
        current[column-1]++;
        bool isGood = true;
        for(int i = 0; i<n;i++){
            if(current[i] <= points){
                isGood = false;
                break;
            }
        }
        if(isGood){
            points++;
        }
    }

    cout<<points;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e7 + 1000;
long long int a[N] , t , b[N] , ans , mas;
set <int> s;

int main () {
    cin >> n >> m;
	for(int i = 0 ; i < m ;i++){
		cin >> a[i] ;
		b[a[i]]++ ;
	}
	for(int i = 1 ; i < N ; i++){
		if(b[i]) ans = min(ans , b[i]) ;
	}
	cout << ans;
	return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e7 + 1000;
long long int a[N] , b[N] , ans ,mn = 1e9;

int main () {
    long long int n , m;
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++ ) {
        cin >> a[i];
        b[a[i]]++;
    }
    for(int i = 1 ; i <= n ; i++ ) {
        mn = min(mn , b[i]);
    }
    cout << mn;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e7 + 1000;
long long int a[N] , t , m , n , b[N] , ans , mas;
set <int> s;

int main () {
    cin >> n >> m;
	for(int i = 0 ; i < m ;i++){
		cin >> a[i] ;
		b[a[i]]++ ;
	}
	for(int i = 1 ; i < N ; i++){
		if(b[i]) ans = min(ans , b[i]) ;
	}
	cout << ans;
	return 0 ;
}


#include<iostream>
#define HuXuancheng 9999
using namespace std;

int main()
{
	int n,m,num,i,min,minn;
	cin >> n >> m;
	int a[1000] = {};
	for (i=1;i<=m;i++)
	{
		cin >> num;
		a[num]++;
	}
	min = HuXuancheng;
	minn = 0;
	for (i=1;i<=n;i++)
	    if ((a[i] < min)&&(a[i] != 0))
	    {
	    	min = a[i];
	    	minn = i;
		}
	cout << minn;
}


#include<iostream>
#define HuXuancheng 9999
using namespace std;

int main()
{
	int n,m,num,i,min,minn;
	cin >> n >> m;
	int a[1001] = {};
	for (i=1;i<=m;i++)
	{
		cin >> num;
		a[num]++;
	}
	min = HuXuancheng;
	minn = 0;
	for (i=1;i<=n;i++)
	    if ((a[i] < min)&&(a[i] != 0))
	    {
	    	min = a[i];
	    	minn = i;
		}
	cout << minn;
}


#include <iostream>
#include <cstring>
using namespace std;
int main(){
    int s[1001],n,m,a,minn=1000;
    memset(s,0,sizeof(s));
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>a;
        s[a]++;
    }
    for(int i=1;i<=n;i++)
        if(s[i]<minn) minn=s[i];
    cout<<minn<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr[100009];
int main()
{
    int n,m,i,x,y;
    cin>>n>>m;
    for(i=1; i<=m; i++)
    {
        cin>>y;
        arr[y]++;
    }
    int k = arr[1];
    for(i=1; i<=n; i++)
    {
        k = min(k,arr[i]);
    }
    cout<<k;
}


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

int main()
{
    int n,m,i,cnt=0,a;
    cin>>n>>m;
    for(i=0; i<m; i++)
    {
        cin>>a;
        if(a == n)
            cnt++;
    }
    cout<<cnt;
}


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

int main()
{
    int n,m,a,i,j,k,cnt;
    cin>>n>>m;
    int arr[m+10];
    for(i=0; i<m; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+m);
    for(i=1; i<=n; i++)
    {
         cnt=0;
        for(j=0; j<m; j++)
        {
            if(i==arr[j])
                cnt++;

        }
       k = min(cnt,1000007);

    }
    cout<<k;

}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int a[1001];
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    for(int i = 1;i <= m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < m; i++){
        int t = 0;
        for(int j = 0; j < n; j++){
            if(a[j] == 0) t++;
            else a[j]--;
        }
        if(t > 0) break;
        else d++;
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int a[1001] = {};
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    for(int i = 1;i <= m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < m; i++){
        int t = 0;
        for(int j = 0; j < n; j++){
            if(a[j] == 0) t++;
            else a[j]--;
        }
        if(t > 0) break;
        else d++;
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    int a[1010];
    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < m; i++){
        int t = 0;
            for(int i = 0; i < n; i++){
                cout << a[i] << ' ';
            }
        for(int j = 0; j < n; j++){
            if(a[j] - 1 == 0){
                d++;
                t++;
                break;
                }
            else a[j]--;
            }
            if(t > 0) break;
            else d++;
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    int a[1010];
    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < m; i++){
        int t = 0;
            //for(int i = 0; i < n; i++){
            //    cout << a[i] << ' ';
           // }
        for(int j = 0; j < n; j++){
            if(a[j] - 1 == 0){
                d++;
                t++;
                break;
                }
            else a[j]--;
            }
            if(t > 0) break;
            else d++;
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    int a[1010];
    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < m; i++){
        int t = 0;
        for(int j = 0; j < n; j++){
            if(a[j] == 0) t++;
            else a[j]--;
        }
        if(t > 0) break;
        else d++;
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    int a[1010];
    for(int i = 1;i <= m;i++){
        int k;
        cin >> k;
        a[k]++;
        }
    for(int i = 1; i <= m; i++){
        int t = 0;
        for(int j = 1; j <= n; j++){
            if(a[j] == 0) t++;
            else a[j]--;
        }
        if(t > 0) break;
        else d++;
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,m,d = 1111;
    cin >> n >> m; // колонок и квадратов
    int a[1010] = {};
    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < n; i++){
        if(a[i] < d) d = a[i];
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,m,d = 1111;
    cin >> n >> m; // колонок и квадратов
    int a[1010];
    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < n; i++){
        if(a[i] < d) d = a[i];
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    int a[1010];
    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < m; i++){
        int t = 0;
           // for(int i = 0; i < n; i++){
           //     cout << a[i] << ' ';
            //}
        for(int j = 0; j < n; j++){
            if(a[j] == 0) t++;
            else a[j]--;
        }
        if(t == 0) d++;
        else {
            cout << d;
            return 0;
            }
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int a[1001];
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < m; i++){
        int t = 0;
        for(int j = 0; j < n; j++){
            if(a[j] == 0) t++;
            else a[j]--;
        }
        if(t > 0) break;
        else d++;
        }
        cout << d;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,m,d = 0;
    cin >> n >> m; // колонок и квадратов
    int a[1010];
    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        a[k-1]++;
        }
    for(int i = 0; i < m; i++){
        int t = 0;
            //for(int i = 0; i < n; i++){
           //     cout << a[i] << ' ';
           // }
        for(int j = 0; j < n; j++){
            if(a[j] == 0){
                cout << d;
                return 0;
                }
            else a[j]--;
            }
            d++;
        }
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <set>
// #include<bits/stdc++.h>
using namespace std;

#define pb                          push_back

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0);

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

    vector<int> a(n);
    for(int i=0; i<m; ++i) {
        int tmp;
        cin >> tmp;
        a[tmp-1]++;
    }

    cout << *min_element(a.begin(),a.end()) << endl;

    return 0;
}


#include <iostream>
#include <queue>
#include <vector>

using namespace std;
#define mp                          make_pair
#define f                           first
#define sc                          second
#define pb                          push_back
typedef pair<int,int> PP;

int main() {
	ios_base::sync_with_stdio(0);

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

	vector<int> arr;
	for(int i=0; i<m; ++i)	{
		int tmp;
		cin >> tmp;
		arr.pb(tmp);
	}

	int ans = INT_MAX;
	for(int i=0; i<m; ++i)	{
		int cnt = 0;
		for(int j=0; j<m; ++j) {
			if(arr[i] == arr[j]) {
				++cnt;
			}
		}
		ans = min(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <set>
#include<bits/stdc++.h>
using namespace std;

#define pb                          push_back

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0);

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

    vector<int> a(n);
    for(int i=0; i<m; ++i) {
        int tmp;
        cin >> tmp;
        a[tmp-1]++;
    }

    cout << *min_element(a.begin(),a.end()) << endl;

    return 0;
}


#include <iostream>
#include <queue>
#include <vector>
#include <set>

using namespace std;
#define mp                          make_pair
#define f                           first
#define sc                          second
#define pb                          push_back
typedef pair<int,int> PP;

int main() {
	ios_base::sync_with_stdio(0);

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

	vector<int> arr;
	set<int> s;
	for(int i=0; i<m; ++i)	{
		int tmp;
		cin >> tmp;
		arr.pb(tmp);
		s.insert(tmp);
	}

	int ans = INT_MAX;
	for(auto it = s.begin(); it != s.end(); ++it)	{
		int cnt = 0;
		for(int j=0; j<m; ++j) {
			if(*it == arr[j]) {
				++cnt;
			}
		}
		ans = min(ans, cnt);
	}

	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <queue>
#include <vector>
#include <set>

using namespace std;
#define mp                          make_pair
#define f                           first
#define sc                          second
#define pb                          push_back
typedef pair<int,int> PP;

int main() {
	ios_base::sync_with_stdio(0);

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

	vector<int> arr;
	set<int> s;
	for(int i=0; i<m; ++i)	{
		int tmp;
		cin >> tmp;
		arr.pb(tmp);
		s.insert(tmp);
	}

	int ans = INT_MAX;
	for(auto it = s.begin(); it != s.end(); ++it)	{
		int cnt = 0;
		for(int j=0; j<m; ++j) {
			if(*it == arr[j]) {
				++cnt;
			}
		}
		ans = min(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}


#define dbg(...) ;
#define db(...) ;
#include "bits/stdc++.h"
#define IO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL)
#define ll long long
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl '\n'
#define all(something) something.begin(), something.end()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define nl cout << endl
#define PI 3.14159265358979323846
using namespace std;
const int MAX = 2e5 + 9;
const ll mod = 1e9 + 7;
vector<bool> prime(MAX, 1);
vector<int> spf(MAX, 1), primes;
void sieve() {
   prime[0] = prime[1] = 0;
   spf[2] = 2;
   for (ll i = 4; i < MAX; i += 2) {
      spf[i] = 2;
      prime[i] = 0;
   }
   primes.pb(2);
   for (ll i = 3; i < MAX; i += 2) {
      if (prime[i]) {
         primes.pb(i);
         spf[i] = i;
         for (ll j = i * i; j < MAX; j += i) {
            prime[j] = 0;
            if (spf[j] == 1) {
               spf[j] = i;
            }
         }
      }
   }
}
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree< pair<int,int> ,null_type,less< pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template <typename T>
void in(T &x) {
   cin >> x;
}
template <typename T, typename U>
void in(T &x, U &y) {
   cin >> x >> y;
}
template <typename T, typename U, typename V>
void in(T &x, U &y, V &z) {
   cin >> x >> y >> z;
}
template <typename T>
void ps(T x) {
   cout << x << " ";
}
template <typename T>
void ps(const vector<T> &x, int n) {
   for (int i = 0; i < n; i++) {
      cout << x[i];
      (i == n - 1) ? cout << endl : cout << " ";
   }
}
template <typename T>
void pl(T x) {
   cout << x << endl;
}
template <typename T>
void pl(const vector<T> &x, int n) {
   for (int i = 0; i < n; i++) {
      cout << x[i] << "\n";
   }
}
template <typename T>
T power(T a, T b) {
   T res = 1;
   while (b) {
      if (b & 1) {
         res = res * a;
      }
      a = a * a;
      b = b >> 1;
   }
   return res;
}
template <typename T>
T power(T a, T b, T m) {
   T res = 1;
   while (b) {
      if (b & 1) {
         res = (res * a) % m;
      }
      a = (a * a) % m;
      b = b >> 1;
   }
   return res % m;
}
void virtual_main() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   freopen("error.txt", "w", stderr);
#endif
}
// #define int long long
int n, m;
vector<int> v(MAX), colorsCount(MAX);
int check(int len) {
   vector<int> a(m + 1);
   int sum = 0;
   int cnt = 0;
   for (int i = 1; i <= m; i++) {
      a[i] = colorsCount[i];
      if (a[i] == 0) {
         cnt++;
      }
      sum += a[i];
   }
   for (int i = 0; i < len; i++) {
      int col = v[i];
      a[col]--;
      if (a[col] == 0) cnt++;
   }
   // dbg(len, a, cnt);
   int ans = INT_MAX;
   if (cnt == m) {
      ans = min(ans, len - sum);
      return ans;
   }
   int lb = 0, ub = len;
   while (ub < n) {
      int ubCol = v[ub];
      int lbCol = v[lb];
      a[lbCol]++;
      if (a[lbCol] == 1) cnt--;
      a[ubCol]--;
      if (a[ubCol] == 0) cnt++;
      if (cnt == m) {
         ans = min(ans, len - sum);
         return ans;
      }
      ub++;
      lb++;
   }
   return -1;
}
void real_main() {
   cin >> n >> m;
   for (int i = 0; i < n; i++) {
      cin >> v[i];
   }
   for (int i = 0; i < m; i++) {
      cin >> colorsCount[i + 1];
   }
   int lb = 0, rb = n, ans = INT_MAX;
   while (lb <= rb) {
      int mb = (lb + rb) / 2;
      int say = check(mb);
      if (say != -1) {
         ans = min(ans, say);
         rb = mb - 1;
      } else {
         lb = mb + 1;
      }
   }
   (ans == INT_MAX) ? pl(-1) : pl(ans);
}
signed main() {
   IO;
   virtual_main();
   int test_cases = 1;
   // cin >> test_cases;
   for (int i = 1; i <= test_cases; i++) {
      // cout << "Case #" << tc << ": ";
      real_main();
   }
   return 0;
}


#define dbg(...) ;
#define db(...) ;
#include "bits/stdc++.h"
#define IO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL)
#define ll long long
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl '\n'
#define all(something) something.begin(), something.end()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define nl cout << endl
#define PI 3.14159265358979323846
using namespace std;
const int MAX = 2e5 + 9;
const ll mod = 1e9 + 7;
vector<bool> prime(MAX, 1);
vector<int> spf(MAX, 1), primes;
void sieve() {
   prime[0] = prime[1] = 0;
   spf[2] = 2;
   for (ll i = 4; i < MAX; i += 2) {
      spf[i] = 2;
      prime[i] = 0;
   }
   primes.pb(2);
   for (ll i = 3; i < MAX; i += 2) {
      if (prime[i]) {
         primes.pb(i);
         spf[i] = i;
         for (ll j = i * i; j < MAX; j += i) {
            prime[j] = 0;
            if (spf[j] == 1) {
               spf[j] = i;
            }
         }
      }
   }
}
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree< pair<int,int> ,null_type,less< pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template <typename T>
void in(T &x) {
   cin >> x;
}
template <typename T, typename U>
void in(T &x, U &y) {
   cin >> x >> y;
}
template <typename T, typename U, typename V>
void in(T &x, U &y, V &z) {
   cin >> x >> y >> z;
}
template <typename T>
void ps(T x) {
   cout << x << " ";
}
template <typename T>
void ps(const vector<T> &x, int n) {
   for (int i = 0; i < n; i++) {
      cout << x[i];
      (i == n - 1) ? cout << endl : cout << " ";
   }
}
template <typename T>
void pl(T x) {
   cout << x << endl;
}
template <typename T>
void pl(const vector<T> &x, int n) {
   for (int i = 0; i < n; i++) {
      cout << x[i] << "\n";
   }
}
template <typename T>
T power(T a, T b) {
   T res = 1;
   while (b) {
      if (b & 1) {
         res = res * a;
      }
      a = a * a;
      b = b >> 1;
   }
   return res;
}
template <typename T>
T power(T a, T b, T m) {
   T res = 1;
   while (b) {
      if (b & 1) {
         res = (res * a) % m;
      }
      a = (a * a) % m;
      b = b >> 1;
   }
   return res % m;
}
void virtual_main() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   freopen("error.txt", "w", stderr);
#endif
}
// #define int long long
int n, m;
vector<int> v(MAX), colorsCount(MAX);
int check(int len) {
   vector<int> a(m + 1);
   int sum = 0;
   for (int i = 1; i <= m; i++) {
      a[i] = colorsCount[i];
      sum += a[i];
   }
   int cnt = 0;
   for (int i = 0; i < len; i++) {
      int col = v[i];
      a[col]--;
      if (a[col] == 0) cnt++;
   }
   dbg(a, cnt);
   int ans = INT_MAX;
   if (cnt == m) {
      ans = min(ans, len - sum);
      return ans;
   }
   int lb = 0, ub = len;
   while (ub < n) {
      int ubCol = v[ub];
      int lbCol = v[lb];
      a[lbCol]++;
      if (a[lbCol] == 1) cnt--;
      a[ubCol]--;
      if (a[ubCol] == 0) cnt++;
      if (cnt == m) {
         ans = min(ans, len - sum);
         return ans;
      }
      ub++;
      lb++;
   }
   return -1;
}
void real_main() {
   cin >> n >> m;
   for (int i = 0; i < n; i++) {
      cin >> v[i];
   }
   for (int i = 0; i < m; i++) {
      cin >> colorsCount[i + 1];
   }
   int lb = 0, rb = n, ans = INT_MAX;
   while (lb <= rb) {
      int mb = (lb + rb) / 2;
      int say = check(mb);
      if (say != -1) {
         ans = min(ans, say);
         rb = mb - 1;
      } else {
         lb = mb + 1;
      }
   }
   (ans == INT_MAX) ? pl(-1) : pl(ans);
}
signed main() {
   IO;
   virtual_main();
   int test_cases = 1;
   // cin >> test_cases;
   for (int i = 1; i <= test_cases; i++) {
      // cout << "Case #" << tc << ": ";
      real_main();
   }
   return 0;
}


#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("mmx,sse,sse2")
#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;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
const int maxn = 2e5 + 1;
int n, m, a[maxn], k = 0, o = 0, b[maxn], sz[maxn], cur[maxn], l = 0;
set<ii> S;
vi c[maxn];
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		c[a[i]].push_back(i);
	}
	for(int i = 1; i <= m; ++i) {
		cin >> b[i];
		if(b[i]) ++o;
		l += b[i];
		cur[i] = (int)c[i].size() - 1;
		sz[i] = 0;
	}
	int ans = INT_MAX;
	for(int i = n - 1; i >= 0; --i) {
		int x = a[i];
		if(!b[x]) continue;
		else if(sz[x] == b[x]) {
			S.erase({c[x][cur[x]], x});
			S.insert({c[x][--cur[x]], x});
		}
		else {
			++sz[x];
			if(sz[x] == 1) S.insert({c[x][cur[x]], x});
			if(sz[x] == b[x]) ++k;
		}
		if(k == o) ans = min(ans, S.rbegin()->first - i + 1 - l);
	}
	cout << (ans == INT_MAX ? -1 : ans) << '\n';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))

typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<PII> VPI;

#define REP(i,a,n) for (int i=a;i<n;i++)
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x)		 cerr << #x << " = " << x << endl
#define db2(x, y)	{cerr << #x << " = " << x << "\t";	db(y);		}
#define db3(x, y, z){cerr << #x << " = " << x << "\t";	db2(y,z);	}

template <typename t1, typename t2> inline bool upmax(t1 &a, t2 b) { if (a<(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename t1, typename t2> inline bool upmin(t1 &a, t2 b) { if (a>(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename T>inline bool pal(T &x){ int n = SZ(x); REP(i, 0, n / 2) { if (x[i] != x[n

- i - 1]) return 0; } return 1; }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }

int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

inline ll mp(ll a, ll b) { return (a << 31) + b; }

class PQ_compare{
public:
	bool operator()(const int a, const int b) const {
		return 1;
	}
};

const int INF = 1000000404;
const ll  LINF = 4000000000000000404ll;
const ll  MOD = 1000000007ll;
const ld  PI = acos(-1.0);
const ld  EPS = 1e-9;

int SQ = 404;

#define debug 1
#define N 211111
int a[N];
int n,m;
int k[N];
int cnt[N];

void solve()
{
    cin>>n>>m;
    int f=0;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=m;i++) {cin>>k[i];f+=k[i];}
    int l=1,r=0;
    int now=0;
    int ans=n;
    while (r<=n) {
        while (now!=m&&r<n) {
            r++;
            int x=a[r];
            cnt[x]++;
            if (cnt[x]==k[x]) now++;
        }
        if (now!=m) break;
        while (cnt[a[l]]>k[a[l]]) {
            cnt[a[l]]--;
            l++;
        }
        if (now==m) {
            upmin(ans,r-l+1-f);
        }
        r++;
    }

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

int main()
{

	//freopen("codeforces.in", "r", stdin);
	//freopen("codeforces.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;

	//cin >> t;

	while (t--) solve();
	return 0;
}
/*
7 3
3 3 1 2 1 1 3
3 1 1
8 3
3 3 1 2 2 1 1 3
3 1 1

*/


#include <bits/stdc++.h>

using namespace std;

#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))

typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<PII> VPI;

#define REP(i,a,n) for (int i=a;i<n;i++)
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x)		 cerr << #x << " = " << x << endl
#define db2(x, y)	{cerr << #x << " = " << x << "\t";	db(y);		}
#define db3(x, y, z){cerr << #x << " = " << x << "\t";	db2(y,z);	}

template <typename t1, typename t2> inline bool upmax(t1 &a, t2 b) { if (a<(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename t1, typename t2> inline bool upmin(t1 &a, t2 b) { if (a>(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename T>inline bool pal(T &x){ int n = SZ(x); REP(i, 0, n / 2) { if (x[i] != x[n

- i - 1]) return 0; } return 1; }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }

int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

inline ll mp(ll a, ll b) { return (a << 31) + b; }

class PQ_compare{
public:
	bool operator()(const int a, const int b) const {
		return 1;
	}
};

const int INF = 1000000404;
const ll  LINF = 4000000000000000404ll;
const ll  MOD = 1000000007ll;
const ld  PI = acos(-1.0);
const ld  EPS = 1e-9;

int SQ = 404;

#define debug 1
#define N 211111
int a[N];
int n,m;
int k[N];
int cnt[N];
bool can(int f) {
    REP(i,1,m+1) cnt[i]=0;

    int now=0;

    for (int i=1;i<=n;i++) {
        int x=a[i];
        cnt[x]++;
        if (cnt[x]==k[x]) now++;
        //if (cnt[x]==k[x]+1) now--;

        if (i>f) {
                int y=a[i-f];
                cnt[y]--;
                if (cnt[y]==k[y]-1) now--;
          //      if (cnt[y]==k[y]) now++;
        }
        if (now==m) {
            return true;
        }
    }

    return false;
}
void solve()
{
    cin>>n>>m;
    int f=0;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=m;i++) {cin>>k[i];f+=k[i];}
    int now=0;
    int l=f;
    int r=n;
    int ans=-1;

    while (l<=r) {
        int m=(l+r)>>1;
        //db(m);
        if (can(m)) {
            r=m-1;
            ans=m-f;
        } else {
            l=m+1;
        }
    }
    cout<<ans;

}

int main()
{

	//freopen("codeforces.in", "r", stdin);
	//freopen("codeforces.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;

	//cin >> t;

	while (t--) solve();
	return 0;
}
/*
7 3
3 3 1 2 1 1 3
3 1 1
8 3
3 3 1 2 2 1 1 3
3 1 1

*/


#include <bits/stdc++.h>

using namespace std;

#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))

typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<PII> VPI;

#define REP(i,a,n) for (int i=a;i<n;i++)
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x)		 cerr << #x << " = " << x << endl
#define db2(x, y)	{cerr << #x << " = " << x << "\t";	db(y);		}
#define db3(x, y, z){cerr << #x << " = " << x << "\t";	db2(y,z);	}

template <typename t1, typename t2> inline bool upmax(t1 &a, t2 b) { if (a<(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename t1, typename t2> inline bool upmin(t1 &a, t2 b) { if (a>(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename T>inline bool pal(T &x){ int n = SZ(x); REP(i, 0, n / 2) { if (x[i] != x[n

- i - 1]) return 0; } return 1; }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }

int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

inline ll mp(ll a, ll b) { return (a << 31) + b; }

class PQ_compare{
public:
	bool operator()(const int a, const int b) const {
		return 1;
	}
};

const int INF = 1000000404;
const ll  LINF = 4000000000000000404ll;
const ll  MOD = 1000000007ll;
const ld  PI = acos(-1.0);
const ld  EPS = 1e-9;

int SQ = 404;

#define debug 1
#define N 211111
int a[N];
int n,m;
int k[N];
int cnt[N];

void solve()
{
    cin>>n>>m;
    int f=0;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=m;i++) {cin>>k[i];f+=k[i];}
    int l=1,r=0;
    int now=0;
    int ans=n;
    while (r<=n) {
        while (now!=m&&r<n) {
            r++;
            int x=a[r];
            cnt[x]++;
            if (cnt[x]==k[x]) now++;
        }
        if (now!=m) break;
        while (cnt[a[l]]!=k[a[l]]) {
            cnt[a[l]]--;
            l++;
        }
        if (now==m) {
            upmin(ans,r-l+1-f);
        }
        r++;
    }

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

int main()
{

	//freopen("codeforces.in", "r", stdin);
	//freopen("codeforces.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;

	//cin >> t;

	while (t--) solve();
	return 0;
}
/*
7 3
3 3 1 2 1 1 3
3 1 1
8 3
3 3 1 2 2 1 1 3
3 1 1

*/


#include <bits/stdc++.h>

using namespace std;

#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))

typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<PII> VPI;

#define REP(i,a,n) for (int i=a;i<n;i++)
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x)		 cerr << #x << " = " << x << endl
#define db2(x, y)	{cerr << #x << " = " << x << "\t";	db(y);		}
#define db3(x, y, z){cerr << #x << " = " << x << "\t";	db2(y,z);	}

template <typename t1, typename t2> inline bool upmax(t1 &a, t2 b) { if (a<(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename t1, typename t2> inline bool upmin(t1 &a, t2 b) { if (a>(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename T>inline bool pal(T &x){ int n = SZ(x); REP(i, 0, n / 2) { if (x[i] != x[n

- i - 1]) return 0; } return 1; }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }

int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

inline ll mp(ll a, ll b) { return (a << 31) + b; }

class PQ_compare{
public:
	bool operator()(const int a, const int b) const {
		return 1;
	}
};

const int INF = 1000000404;
const ll  LINF = 4000000000000000404ll;
const ll  MOD = 1000000007ll;
const ld  PI = acos(-1.0);
const ld  EPS = 1e-9;

int SQ = 404;

#define debug 1
#define N 211111
int a[N];
int n,m;
int k[N];
int cnt[N];

void solve()
{
    cin>>n>>m;
    int f=0;
    for (int i=1;i<=n;i++) cin>>a[i];
    int now=0;
    for (int i=1;i<=m;i++) {cin>>k[i];f+=k[i]; if (k[i]==0) now++;}
    int l=1,r=0;
    int ans=n;

    while (l<=n) {
        while (r<n&&now!=m) {
            r++;
            cnt[a[r]]++;
            if (cnt[a[r]]==k[a[r]]) now++;
        }
        if (now!=m) break;
        if (now==m) {
            upmin(ans,r-l+1-f);
        }
        cnt[a[l]]--;
        if (cnt[a[l]]==k[a[l]]-1) now--;
        l++;
    }

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

int main()
{

	//freopen("codeforces.in", "r", stdin);
	//freopen("codeforces.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;

	//cin >> t;

	while (t--) solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))

typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<PII> VPI;

#define REP(i,a,n) for (int i=a;i<n;i++)
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x)		 cerr << #x << " = " << x << endl
#define db2(x, y)	{cerr << #x << " = " << x << "\t";	db(y);		}
#define db3(x, y, z){cerr << #x << " = " << x << "\t";	db2(y,z);	}

template <typename t1, typename t2> inline bool upmax(t1 &a, t2 b) { if (a<(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename t1, typename t2> inline bool upmin(t1 &a, t2 b) { if (a>(t1)b) { a = (t1)

b; return true; } else return false; }
template <typename T>inline bool pal(T &x){ int n = SZ(x); REP(i, 0, n / 2) { if (x[i] != x[n

- i - 1]) return 0; } return 1; }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }

int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

inline ll mp(ll a, ll b) { return (a << 31) + b; }

class PQ_compare{
public:
	bool operator()(const int a, const int b) const {
		return 1;
	}
};

const int INF = 1000000404;
const ll  LINF = 4000000000000000404ll;
const ll  MOD = 1000000007ll;
const ld  PI = acos(-1.0);
const ld  EPS = 1e-9;

int SQ = 404;

#define debug 1
#define N 211111
int a[N];
int n,m;
int k[N];
int cnt[N];

void solve()
{
    cin>>n>>m;
    int f=0;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=m;i++) {cin>>k[i];f+=k[i];}
    int l=1,r=0;
    int now=0;
    int ans=n;
    while (l<=n) {

        while (r<n&&now!=m) {
            r++;
            cnt[a[r]]++;
            if (cnt[a[r]]==k[a[r]]) now++;
        }
        if (now!=m) break;
        if (now==m) {
            upmin(ans,r-l+1-f);
        }
        cnt[a[l]]--;
        if (cnt[a[l]]==k[a[l]]-1) now--;
        l++;
    }

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

int main()
{

	//freopen("codeforces.in", "r", stdin);
	//freopen("codeforces.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;

	//cin >> t;

	while (t--) solve();
	return 0;
}
/*
7 3
3 3 1 2 1 1 3
3 1 1
8 3
3 3 1 2 2 1 1 3
3 1 1

*/


/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int a[SIZE],b[SIZE],now[SIZE];
int main(){
    int n,m;
    R(n,m);
    FOR(i,1,n)R(a[i]);
    int need=0;
    FOR(i,1,m){
        R(b[i]);
        need+=b[i];
    }
    int rr=1;
    FOR(i,1,m){
        while(rr<=n&&now[i]<b[i]){
            now[a[rr]]++;
            rr++;
        }
    }
    FOR(i,1,m){
        if(b[i]>now[i]){
            W(-1);
            return 0;
        }
    }
    int an=rr-1-need;
    FOR(i,2,n){
        now[a[i-1]]--;
        while(rr<=n&&now[a[i-1]]<b[a[i-1]]){
            now[a[rr]]++;
            rr++;
        }
        if(now[a[i-1]]<b[a[i-1]])break;
        an=min(an,rr-i-need);
    }
    W(an);
    return 0;
}


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

bool Check(int mid){
    for(int i=0;i<m;i++){
        NonAbs[i]=Need[i];
        Count[i]=Need[i];
    }

    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;
Count.resize(m);
NonAbs.resize(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;
}


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

bool Check(int mid){
    for(int i=0;i<m;i++){
        NonAbs[i]=Need[i];
        Count[i]=Need[i];
    }

    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;
Count.resize(m);
NonAbs.resize(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;}
else low=mid+1;

}

if(Check(low))End(low);

else
cout <<-1<<endl;
}