//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    Forn(i,n) for(int i=1;i<=n;i++)
#define    Fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    min4(a,b,c,d)   min(min(a,b),min(c,d))
#define    max4(a,b,c,d)   max(max(a,b),max(c,d))
#define    Max(a)  *max_element(a,a+sizeof(a)/sizeof(a[0]))
#define    Min(a)  *min_element(a,a+sizeof(a)/sizeof(a[0]))
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    mod    1e9+7 //1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    YES    printf("YES\n")
#define    NO     printf("NO\n")
#define    Erase(s) s.erase(unique(s.begin(),s.end()),s.end())
//%%%%%%%%%%%%%p%%%a%%%r%%%v%%%e%%%z%%%%%%%%%%%%%//

int main()
{
MP;
    //int T;cin>>T;while(T--)
    {
        int a[4];
        For(i,4) cin >> a[i];
        cout << Min(a);
    }
    cerr<<endl<<(float)clock()/(float)CLOCKS_PER_SEC<<" sec"<<endl;
End;
}

#include<bits/stdc++.h>
#define MAX 2000
#define MOD 998244353
using namespace std;
vector<int> v[MAX+10];
bool visited[MAX+10];
int ans = 0;
void dfs(int x)
{
	visited[x] = true;
	++ans;
	for(int y:v[x])
	{
		if(visited[y])
			continue;
		dfs(y);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	while(m--)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
			visited[j] = false;
		dfs(i);
	}
	cout<<ans<<endl;
	return 0;
}