#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

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

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

vector<int> prime, lpf;

void sieve(int n){
    lpf.resize(n + 1, 1);
    for(int i = 2; i <= n; i++){
        if(lpf[i] == 1){
            lpf[i] = i;
            prime.eb(i);
        }
        for(int j : prime){
            if((ll)j * i > n) break;
            lpf[i * j] = j;
            if(j == lpf[i]) break;
        }
    }
}

int main(){
    StarBurstStream

//    sieve(40000);

    int n;
    cin >> n;
    map<int, int> tmp;
    int mn = MAX;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mn = min(mn, a);
        for(int j = 1; (ll)j * j <= a; j++){
            if(a % j) continue;
            tmp[j] = __gcd(tmp[j], a);
            tmp[a / j] = __gcd(tmp[a / j], a);
        }
    }

    int ans = 0;
    for(pii i : tmp){
        if(i.F == i.S && i.F <= mn) ans++;
    }
    cout << ans << "\n";

    return 0;
}
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int l;
#define M 1000000007
#define loop(i,n)           for(int i=0;i<n;i++)
const l inf = 9e17;
struct triplet
{
    l src;
    l dest;
    l weigh;
};
l sum;
l pa(int n)
{
    l cnt=0;
    for(int i=1;i*i<=n;i++)
    {
        if(i*i==n)
            sum+=i;
        else if(n%i==0)
            {
               sum+=i;
               sum+=(n/i);
            }
 
    }
    return sum%M;
}

l vis[10001];
map<l,vector<l>>mp;
int dfs(l st)
{
    if(vis[st])
        return 0;
    vis[st]=1;
    l ans=0;
    for(auto x:mp[st])
    {
        if(!vis[x])
        {   
            ans+=dfs(x);
        }
    }
    return ans+1;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
 
 
 
 
    l t;
    t=1;
    while(t--)
    {
     
            l n,m;
            cin>>n>>m;
            
            l a,b;
            loop(i,m)
            {
                cin>>a>>b;
                mp[a].push_back(b);
            }
            //vis.resize(n+1);
            l ams=0;
            loop(i,n){
               memset(vis,0,sizeof(vis));
               l z = dfs(i+1);
               //cout<<z<<endl;
               ams+=z;

            }
            cout<<ams;
            
 
    }
 
 
 
 
    return 0;
 
    
}