#include<bits/stdc++.h>
#define MAX 6010
using namespace std;
queue<pair<int, int> >q;
vector<int> g[MAX];
pair<int, int> ls;
int cnt[MAX], n, m, x, y, ans = 0, sum = 0;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> x >> y;
g[y].push_back(x);
cnt[x]++;
}
for(int i = 1; i <= n; i++)
if(!cnt[i]) q.push(make_pair(i, 100));
while(q.size()){
ls = q.front();
q.pop();
ans += ls.second, sum ++;
for(int i = 0; i < g[ls.first].size(); i++){
cnt[g[ls.first][i]]--;
if(!cnt[g[ls.first][i]]) q.push(make_pair(g[ls.first][i], ls.second + 1));
}
}
if(sum == n) cout << ans;
else cout << "no solution";
return 0;
}