from itertools import combinations

class UnionFind():

    def __init__(self, n):

        self.n = n

        self.root = [-1]*(n+1)

        self.rnk = [0]*(n+1)

    def Find_Root(self, x):

        if(self.root[x] < 0):

            return x

        else:

            self.root[x] = self.Find_Root(self.root[x])

            return self.root[x]

    def Unite(self, x, y):

        x = self.Find_Root(x)

        y = self.Find_Root(y)

        if(x == y):

            return 

        elif(self.rnk[x] > self.rnk[y]):

            self.root[x] += self.root[y]

            self.root[y] = x

        else:

            self.root[y] += self.root[x]

            self.root[x] = y

            if(self.rnk[x] == self.rnk[y]):

                self.rnk[y] += 1

    def isSameGroup(self, x, y):

        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):

        return -self.root[self.Find_Root(x)]



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

uf=UnionFind(n)

e=[]

ans=[]

for _ in range(m):

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

  e.append((a,b))

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

for i,j in e[::-1]:

  ans.append(n_m)

  if not uf.isSameGroup(i,j):

    k=uf.Count(i)*uf.Count(j)

    n_m-=k

    uf.Unite(i,j)

for i in ans[::-1]:

  print(i)
class UnionFind():

  def __init__(self, n=10**6):

    self.n=n

    self.root=[-1]*(n+1)

    self.rnk=[0]*(n+1)

  def find(self, x):

    if(self.root[x]<0):

      return x

    else:

      self.root[x]=self.find(self.root[x])

      return self.root[x]

  def unite(self, x, y):

    x=self.find(x)

    y=self.find(y)

    if(x==y):return 

    elif(self.rnk[x] > self.rnk[y]):

      self.root[x]+=self.root[y]

      self.root[y]=x

    else:

      self.root[y]+=self.root[x]

      self.root[x]=y

      if(self.rnk[x]==self.rnk[y]):

        self.rnk[y]+=1

  def same(self, x, y):

    return self.find(x)==self.find(y)

  def count(self, x):

    return -self.root[self.find(x)]

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

uf=UnionFind(n)

a=[0]*m

b=[0]*m

for i in range(m):

  a[i],b[i]=map(int,input().split())

c=[1]*(n+1)

ans=[]

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

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

  ans+=[nm]

  x,y=a[i],b[i]

  if uf.same(x,y):continue

  nm-=uf.count(x)*uf.count(y)

  uf.unite(x,y)

print(*ans[::-1],sep='\n')

from itertools import combinations


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        self.rnk = [0] * (n + 1)

    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]


n, m = list(map(int, input().split()))
uf = UnionFind(n)
e = []
ans = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    e.append((a, b))
n_m = n * (n - 1) // 2
for i, j in e[::-1]:
    ans.append(n_m)
    if not uf.isSameGroup(i, j):
        k = uf.Count(i) * uf.Count(j)
        n_m -= k
        uf.Unite(i, j)
for i in ans[::-1]:
    print(i)

class UnionFind:
    def __init__(self, n=10**6):
        self.n = n
        self.root = [-1] * (n + 1)
        self.rnk = [0] * (n + 1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def count(self, x):
        return -self.root[self.find(x)]


n, m = map(int, input().split())
uf = UnionFind(n)
a = [0] * m
b = [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())
c = [1] * (n + 1)
ans = []
nm = n * (n - 1) // 2
for i in range(m - 1, -1, -1):
    ans += [nm]
    x, y = a[i], b[i]
    if uf.same(x, y):
        continue
    nm -= uf.count(x) * uf.count(y)
    uf.unite(x, y)
print(*ans[::-1], sep="\n")

-from itertools import combinations - - -    def __init__(self, n): +    def __init__(self, n=10**6): -    def Find_Root(self, x): +    def find(self, x): -            self.root[x] = self.Find_Root(self.root[x]) +            self.root[x] = self.find(self.root[x]) -    def Unite(self, x, y): -        x = self.Find_Root(x) -        y = self.Find_Root(y) +    def unite(self, x, y): +        x = self.find(x) +        y = self.find(y) -    def isSameGroup(self, x, y): -        return self.Find_Root(x) == self.Find_Root(y) +    def same(self, x, y): +        return self.find(x) == self.find(y) -    def Count(self, x): -        return -self.root[self.Find_Root(x)] +    def count(self, x): +        return -self.root[self.find(x)] -n, m = list(map(int, input().split())) +n, m = map(int, input().split()) -e = [] +a = [0] * m +b = [0] * m +for i in range(m): +    a[i], b[i] = map(int, input().split()) +c = [1] * (n + 1) -for _ in range(m): -    a, b = list(map(int, input().split())) -    e.append((a, b)) -n_m = n * (n - 1) // 2 -for i, j in e[::-1]: -    ans.append(n_m) -    if not uf.isSameGroup(i, j): -        k = uf.Count(i) * uf.Count(j) -        n_m -= k -        uf.Unite(i, j) -for i in ans[::-1]: -    print(i) +nm = n * (n - 1) // 2 +for i in range(m - 1, -1, -1): +    ans += [nm] +    x, y = a[i], b[i] +    if uf.same(x, y): +        continue +    nm -= uf.count(x) * uf.count(y) +    uf.unite(x, y) +print(*ans[::-1], sep="\n")