N, Q = list(map(int, input().split()))

A = [list(map(int, input().split())) for _ in range(Q)]

res = [0] * (Q - 1) + [N * (N - 1) // 2]

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



uf = UnionFind(N)

convenience = [0] * (N + 1)

for i in range(Q - 1, 0, -1):

  res[i - 1] = res[i]

  if uf.Find_Root(A[i][0]) != uf.Find_Root(A[i][1]):

    res[i - 1] -= uf.Count(A[i][0]) * uf.Count(A[i][1])

    a, b = uf.Count(A[i][0]), uf.Count(A[i][1])

    uf.Unite(A[i][0], A[i][1])

  #print(uf.root, res, a, b)

for i in range(Q):

  print((res[i]))
import sys

input = sys.stdin.readline

N, M = list(map(int, input().split()))



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



uf = UnionFind(N)

e = []

for _ in range(M):

  u, v = list(map(int, input().split()))

  e.append((u, v))

e.reverse()

res = [0] * M

res[0] = N * (N - 1) // 2

for i in range(M - 1):

  u, v = e[i]

  res[i + 1] = res[i]

  if uf.isSameGroup(u, v):

    continue

  else:

    res[i + 1] -= uf.Count(u) * uf.Count(v)

  uf.Unite(u, v)

res.reverse()

for r in res: print(r)
N, Q = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(Q)]
res = [0] * (Q - 1) + [N * (N - 1) // 2]


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


uf = UnionFind(N)
convenience = [0] * (N + 1)
for i in range(Q - 1, 0, -1):
    res[i - 1] = res[i]
    if uf.Find_Root(A[i][0]) != uf.Find_Root(A[i][1]):
        res[i - 1] -= uf.Count(A[i][0]) * uf.Count(A[i][1])
        a, b = uf.Count(A[i][0]), uf.Count(A[i][1])
        uf.Unite(A[i][0], A[i][1])
    # print(uf.root, res, a, b)
for i in range(Q):
    print((res[i]))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))


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


uf = UnionFind(N)
e = []
for _ in range(M):
    u, v = list(map(int, input().split()))
    e.append((u, v))
e.reverse()
res = [0] * M
res[0] = N * (N - 1) // 2
for i in range(M - 1):
    u, v = e[i]
    res[i + 1] = res[i]
    if uf.isSameGroup(u, v):
        continue
    else:
        res[i + 1] -= uf.Count(u) * uf.Count(v)
    uf.Unite(u, v)
res.reverse()
for r in res:
    print(r)

-N, Q = list(map(int, input().split())) -A = [list(map(int, input().split())) for _ in range(Q)] -res = [0] * (Q - 1) + [N * (N - 1) // 2] +import sys + +input = sys.stdin.readline +N, M = list(map(int, input().split())) -convenience = [0] * (N + 1) -for i in range(Q - 1, 0, -1): -    res[i - 1] = res[i] -    if uf.Find_Root(A[i][0]) != uf.Find_Root(A[i][1]): -        res[i - 1] -= uf.Count(A[i][0]) * uf.Count(A[i][1]) -        a, b = uf.Count(A[i][0]), uf.Count(A[i][1]) -        uf.Unite(A[i][0], A[i][1]) -    # print(uf.root, res, a, b) -for i in range(Q): -    print((res[i])) +e = [] +for _ in range(M): +    u, v = list(map(int, input().split())) +    e.append((u, v)) +e.reverse() +res = [0] * M +res[0] = N * (N - 1) // 2 +for i in range(M - 1): +    u, v = e[i] +    res[i + 1] = res[i] +    if uf.isSameGroup(u, v): +        continue +    else: +        res[i + 1] -= uf.Count(u) * uf.Count(v) +    uf.Unite(u, v) +res.reverse() +for r in res: +    print(r)