for e in iter(input,'0'):

 R=[set()for _ in[0]*-~int(e)]

 for _ in[0]*int(eval(input())):

  a,b=list(map(int,input().split()))

  R[a]|={b}

  if a-1:R[b]|={a}

 for m in set(R[1]):

  R[1]|=R[m]

 print((len(R[1])))

for e in iter(input,'0'):

 R=[[]for _ in[0]*-~int(e)]

 for _ in[0]*int(eval(input())):

  a,b=list(map(int,input().split()))

  R[a]+=[b];R[b]+=[a]

 for m in R[1][:]:R[1]+=R[m]

 print((len({*R[1]}-{1})))

for e in iter(input, "0"):
    R = [set() for _ in [0] * -~int(e)]
    for _ in [0] * int(eval(input())):
        a, b = list(map(int, input().split()))
        R[a] |= {b}
        if a - 1:
            R[b] |= {a}
    for m in set(R[1]):
        R[1] |= R[m]
    print((len(R[1])))

for e in iter(input, "0"):
    R = [[] for _ in [0] * -~int(e)]
    for _ in [0] * int(eval(input())):
        a, b = list(map(int, input().split()))
        R[a] += [b]
        R[b] += [a]
    for m in R[1][:]:
        R[1] += R[m]
    print((len({*R[1]} - {1})))

-    R = [set() for _ in [0] * -~int(e)] +    R = [[] for _ in [0] * -~int(e)] -        R[a] |= {b} -        if a - 1: -            R[b] |= {a} -    for m in set(R[1]): -        R[1] |= R[m] -    print((len(R[1]))) +        R[a] += [b] +        R[b] += [a] +    for m in R[1][:]: +        R[1] += R[m] +    print((len({*R[1]} - {1})))