#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long ll;

int main() {
    int N, M, A, B;
    cin >> N >> M;
    vector<vector<int>> d(N, vector<int>(N, 1e9)), edge(N);
    rep(i, N) d[i][i] = 0;
    rep(i, M) {
        cin >> A >> B;
        d[A - 1][B - 1] = 1;
        edge[A - 1].push_back(B - 1);
    }
    int ans = 0;
    rep(k, N) {
        vector<bool> done(N, false);
        queue<int> q;
        q.push(k);
        done[k] = true;
        ans++;
        while (!q.empty()) {
            int p = q.front();
            q.pop();
            rep(i, edge[p].size()) {
                int u = edge[p][i];
                if (done[u]) continue;
                q.push(u);
                done[u] = true;
                ans++;
            }
        }
    }
    cout << ans << endl;
}
#include<iostream>             
#include<vector>   
#include<bits/stdc++.h>
#define mod 1000000007
#define pi 3.14159265358979
#define  PRE(x,p) cout<<setprecision(x)<<p; 
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl "\n"
#define high INT_MAX
#define low INT_MIN
#define ll long long int

using namespace std;


void showa(ll a[],ll n){ for(ll i=1;i<=n;i++) cout<<a[i]<<' ';  cout<<endl;  }
void showv(vector<ll>v){ for(ll i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;}
ll modd;
ll power(ll x, ll y) 
{
   ll res = 1;
   x = x % modd; 
  while (y > 0)
  { 
        
        if (y & 1) 
            res = (res * x) % modd; 
  
        
        y = y >> 1; 
        x = (x * x) % modd; 
    } 
    return res; 
}
void solve() 
{ 
   ll n,m;
   cin>>n>>m;
   modd=m*m;
   cout<<(power(10,n)/m) %m;


}
int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

ll t=1;
// cin>>t;
for(ll test=1;test<=t;test++)
{
    // cout<<"CASE #"<<test<<": ";
    solve();
}

return 0;
}