n,m = list(map(int,input().split()))

ab = []

for _ in range(m):

  ab.append(list([int(x)-1 for x in input().split()]))

ab.reverse()

pre = [-1 for _ in range(n)]

num = [ 1 for _ in range(n)]

ans = n * (n-1) // 2

out = []

for i in range(m):

  out.append(ans)

  x,y = ab[i]

  X = []

  while pre[x] != -1:

    X.append(x)

    x = pre[x]

  Y = []

  while pre[y] != -1:

    Y.append(y)

    y = pre[y]

  if x != y:

    ans -= num[x] * num[y]

    if x > y:

      pre[y] = x

      num[x] += num[y]

    else:

      pre[x] = y

      num[y] += num[x]

out.reverse()

for o in out:

  print(o)
n,m = list(map(int,input().split()))

ab = []

for _ in range(m):

  ab.append(list([int(x)-1 for x in input().split()]))

ab.reverse()

pre = [i for i in range(n)]

num = [1 for _ in range(n)]

ans = n * (n-1) // 2

out = []

for i in range(m):

  out.append(ans)

  x,y = ab[i]

  X = []

  while pre[x] != x:

    X.append(x)

    x = pre[x]

  Y = []

  while pre[y] != y:

    Y.append(y)

    y = pre[y]

  if x != y:

    ans -= num[x] * num[y]

    if num[x] >= num[y]:

      win = x

      pre[y] = x

      num[x] += num[y]

    else:

      win = y

      pre[x] = y

      num[y] += num[x]

    for xx in X:

      pre[xx] = win

    for yy in Y:

      pre[yy] = win

out.reverse()

for o in out:

  print(o)
n, m = list(map(int, input().split()))
ab = []
for _ in range(m):
    ab.append(list([int(x) - 1 for x in input().split()]))
ab.reverse()
pre = [-1 for _ in range(n)]
num = [1 for _ in range(n)]
ans = n * (n - 1) // 2
out = []
for i in range(m):
    out.append(ans)
    x, y = ab[i]
    X = []
    while pre[x] != -1:
        X.append(x)
        x = pre[x]
    Y = []
    while pre[y] != -1:
        Y.append(y)
        y = pre[y]
    if x != y:
        ans -= num[x] * num[y]
        if x > y:
            pre[y] = x
            num[x] += num[y]
        else:
            pre[x] = y
            num[y] += num[x]
out.reverse()
for o in out:
    print(o)

n, m = list(map(int, input().split()))
ab = []
for _ in range(m):
    ab.append(list([int(x) - 1 for x in input().split()]))
ab.reverse()
pre = [i for i in range(n)]
num = [1 for _ in range(n)]
ans = n * (n - 1) // 2
out = []
for i in range(m):
    out.append(ans)
    x, y = ab[i]
    X = []
    while pre[x] != x:
        X.append(x)
        x = pre[x]
    Y = []
    while pre[y] != y:
        Y.append(y)
        y = pre[y]
    if x != y:
        ans -= num[x] * num[y]
        if num[x] >= num[y]:
            win = x
            pre[y] = x
            num[x] += num[y]
        else:
            win = y
            pre[x] = y
            num[y] += num[x]
        for xx in X:
            pre[xx] = win
        for yy in Y:
            pre[yy] = win
out.reverse()
for o in out:
    print(o)

-pre = [-1 for _ in range(n)] +pre = [i for i in range(n)] -    while pre[x] != -1: +    while pre[x] != x: -    while pre[y] != -1: +    while pre[y] != y: -        if x > y: +        if num[x] >= num[y]: +            win = x +            win = y +        for xx in X: +            pre[xx] = win +        for yy in Y: +            pre[yy] = win