#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll n, m;
vector<ll> G[N], R[N];
ll id[N], ans[N], root;
ll M[N];
vector<ll> T;
void DFS(ll v) {
	M[v] = 1;
	for (auto u : G[v]) 
		if (!M[u])
			DFS(u);
	T.pb(v);
}
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n - 1 + m; i ++) {
		ll v, u;
		cin >> v >> u;
		G[v].pb(u);
		R[u].pb(v);
	}
	for (int i = 1; i <= n; i ++) {
		if (R[i].size()) continue;
		DFS(i);
	}
	reverse(all(T));
	root = T[0];
	for (int i = 0; i < n; i ++) {
		id[T[i]] = i;
	}
	for (int i = 1; i <= n; i ++) {
		ll pos = -1, v = 0;
		for (auto u : R[i]) {
			if (id[u] > pos) {
				pos = id[u];
				v = u;
			}
		}
		ans[i] = v;
	}
	for (int i = 1; i <= n; i ++) {
		cout << ans[i] <<  '\n';
	}
}
#include <iostream>
using namespace std;
int main()
{
	while (1)
	{
		int a = 0;
		int x = 0;
		int d = 0;
		int aa[10001];
		for (int i = 0; i < 10001; i++)
		{
			aa[i] = 0;
		}
		cin >> x;
		cin >> a;
		if (x == 0 && a == 0)
		{
			break;
		}
		int b[10000];
		int c[10000];
		for (int i = 0; i < a; i++)
		{
			cin >> b[i];
			cin >> c[i];
		}
		for (int i = 0; i < a; i++)
		{
			if (b[i] == 1)
			{
				aa[c[i]] = 1;
				for (int j = 0; j < a; j++)
				{
					if (c[i] == b[j])
					{
						aa[c[j]] = 1;
					}
					if (c[i] == c[j])
					{
						aa[b[j]] = 1;
					}
				}
			}
		}
		for (int i = 2; i <= x; i++)
		{
			if (aa[i] == 1)
			{
				d++;
			}
		}
		cout << d << endl;
	}
	
	return 0;
}