#include <cstring>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e5 + 10, M = 2e5 + 10;
int h[N], e[N], ne[N], idx;
int d[N], q[N];
int f[N];
bool st[N];
int n, m;
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void topsort()
{
int hh = 0, tt = -1;
for (int i = 1; i <= n; i++)
if (!d[i])
q[++tt] = i;
while (hh <= tt)
{
int t = q[hh++];
if (st[t])
continue;
st[t] = true;
for (int i = h[t]; ~i; i = ne[i])
{
int j = e[i];
f[j] = max(f[j], f[t] + 1);
if (--d[j] == 0)
q[++tt] = j;
}
}
}
signed main()
{
memset(h, -1, sizeof h);
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int a, b;
cin >> a >> b;
add(a, b);
d[b]++;
}
for (int i = 1; i <= n; i++)
f[i] = 1;
topsort();
for (int i = 1; i <= n; i++)
cout << f[i] << endl;
return 0;
}