import sys

sys.setrecursionlimit(100000)

input = sys.stdin.readline

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

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

l=[-1]*n

a=[1]*n

b=[input().split() for _ in range(m)]

c=[0]*m+[z]

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

def r(s):

  t=l[s]

  if t<0:

    return s

  else:

    l[s]=r(t)

    return l[s]

def f(s):

  return r(int(s)-1)

for i in range(m-1,-1,-1):

  x,y=list(map(f,b[i]))

  if x!=y:

    l[x]=y

    d[y]=d[x]

    z-=a[x]*a[y]

    a[y]+=a[x]

  c[i]=z

for x in c[1:]:

  print(x)
import sys

sys.setrecursionlimit(100000)

input = sys.stdin.readline

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

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

l=[-1]*n

a=[1]*n

b=[input().split() for _ in range(m)]

c=[0]*m+[z]

def r(s):

  t=l[s]

  if t<0:

    return s

  else:

    l[s]=r(t)

    return l[s]

def f(s):

  return r(int(s)-1)

for i in range(m-1,-1,-1):

  x,y=list(map(f,b[i]))

  if x!=y:

    s,t=a[x],a[y]

    z-=s*t

    if s<t:

      l[x]=y

      a[y]+=s

    else:

      l[y]=x

      a[x]+=t

  c[i]=z

for x in c[1:]:

  print(x)
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
z = n * (n - 1) // 2
l = [-1] * n
a = [1] * n
b = [input().split() for _ in range(m)]
c = [0] * m + [z]
d = [i for i in range(n)]


def r(s):
    t = l[s]
    if t < 0:
        return s
    else:
        l[s] = r(t)
        return l[s]


def f(s):
    return r(int(s) - 1)


for i in range(m - 1, -1, -1):
    x, y = list(map(f, b[i]))
    if x != y:
        l[x] = y
        d[y] = d[x]
        z -= a[x] * a[y]
        a[y] += a[x]
    c[i] = z
for x in c[1:]:
    print(x)

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
z = n * (n - 1) // 2
l = [-1] * n
a = [1] * n
b = [input().split() for _ in range(m)]
c = [0] * m + [z]


def r(s):
    t = l[s]
    if t < 0:
        return s
    else:
        l[s] = r(t)
        return l[s]


def f(s):
    return r(int(s) - 1)


for i in range(m - 1, -1, -1):
    x, y = list(map(f, b[i]))
    if x != y:
        s, t = a[x], a[y]
        z -= s * t
        if s < t:
            l[x] = y
            a[y] += s
        else:
            l[y] = x
            a[x] += t
    c[i] = z
for x in c[1:]:
    print(x)

-d = [i for i in range(n)] -        l[x] = y -        d[y] = d[x] -        z -= a[x] * a[y] -        a[y] += a[x] +        s, t = a[x], a[y] +        z -= s * t +        if s < t: +            l[x] = y +            a[y] += s +        else: +            l[y] = x +            a[x] += t