#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct node
{
int num, i, o;
vector <int> f;
node() {}
node(int num1, int i1, int o1)
{
num = num1;
i = i1;
o = o1;
}
};
int ans[1000001];
int main()
{
int n, m, i, j, a, b;
vector <node> v;
queue <node> q;
cin >> n >> m;
for (i = 0; i <= n; ++i)
v.push_back(node(i, 0, 0));
for (i = 1; i <= m; ++i)
{
cin >> a >> b;
v[a].o++;
v[a].f.push_back(b);
v[b].i++;
}
for (i = 1; i <= n; ++i)
{
if (!v[i].i)
{
q.push(v[i]);
ans[i] = 1;
}
cout << i << ": ";
for (j = 0; j < v[i].f.size(); ++j)
cout << v[i].f[j] << ' ';
cout << ' ' << v[i].i << ' ' << v[i].o << endl;
}
while (!q.empty())
{
cout << q.front().num << ' ';
cout << q.front().o << endl;
for (i = 0; i < q.front().o; ++i)
{
v[q.front().f[i]].i--;
if (!v[q.front().f[i]].i)
{
q.push(node(q.front().f[i], v[q.front().f[i]].i - 1, v[q.front().f[i]].o));
ans[q.front().f[i]] += ans[q.front().num];
}
}
q.pop();
}
for (i = 1; i <= n; ++i)
{
if (!v[i].o)
ans[0] += ans[i];
}
cout << ans[0];
return 0;
}