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

l=[-1]*n

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

c=[0]*m+[n*(n-1)//2]

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]))

  s,t=0,0

  if x!=y:

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

    if s>t:

      l[x]=y

      l[y]+=s

    else:

      l[y]=x

      l[x]+=t

  c[i]=c[i+1]-s*t

for x in c[1:]:

  print(x)
import sys

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

l=[-1]*n

b=[sys.stdin.readline().split() for _ in range(m)]

c=[0]*m+[n*(n-1)//2]

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]))

  s,t=0,0

  if x!=y:

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

    if s>t:

      l[x]=y

      l[y]+=s

    else:

      l[y]=x

      l[x]+=t

  c[i]=c[i+1]-s*t

for x in c[1:]:

  print(x)
n, m = list(map(int, input().split()))
l = [-1] * n
b = [input().split() for _ in range(m)]
c = [0] * m + [n * (n - 1) // 2]


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]))
    s, t = 0, 0
    if x != y:
        s, t = l[x], l[y]
        if s > t:
            l[x] = y
            l[y] += s
        else:
            l[y] = x
            l[x] += t
    c[i] = c[i + 1] - s * t
for x in c[1:]:
    print(x)

import sys

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


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]))
    s, t = 0, 0
    if x != y:
        s, t = l[x], l[y]
        if s > t:
            l[x] = y
            l[y] += s
        else:
            l[y] = x
            l[x] += t
    c[i] = c[i + 1] - s * t
for x in c[1:]:
    print(x)

+import sys + -b = [input().split() for _ in range(m)] +b = [sys.stdin.readline().split() for _ in range(m)]