class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n
        self.count = [1] * n

    def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

    def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

    def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i]


n, m = [int(i) for i in input().split()]
uf = UnionFind(n)
ab = [[int(i) - 1 for i in input().split()] for _ in range(m)]
c = n * (n - 1) // 2
ans = []
for a, b in reversed(ab):
    ans.append(c)
    if uf.is_same_tree(a, b):
        continue
    e = uf.get_root(a)
    f = uf.get_root(b)
    c -= uf.count[e] * uf.count[f]
    uf.merge(a, b)
print("\n".join(map(str, reversed(ans)))) class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n
        self.count = [1] * n

    def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

    def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

    def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i] UnionFind def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n
        self.count = [1] * n

     __init__ self.parent = [-1] * n self.parent self parent [-1] * n [-1] -1 n self.rank = [1] * n self.rank self rank [1] * n [1] 1 n self.count = [1] * n self.count self count [1] * n [1] 1 n self self n n def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

     get_root while self.parent[i] != -1:
            i = self.parent[i]
         self.parent[i] != -1 self.parent[i] self.parent self parent i -1 i = self.parent[i] i self.parent[i] self.parent self parent i return i i self self i i def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

     is_same_tree return self.get_root(i) == self.get_root(j) self.get_root(i) == self.get_root(j) self.get_root(i) self.get_root self get_root i self.get_root(j) self.get_root self get_root j self self i i j j def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i] merge i = self.get_root(i) i self.get_root(i) self.get_root self get_root i j = self.get_root(j) j self.get_root(j) self.get_root self get_root j if i == j:
            return

         i == j i j return if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i] self.rank[i] > self.rank[j] self.rank[i] self.rank self rank i self.rank[j] self.rank self rank j self.parent[j] = i self.parent[j] self.parent self parent j i self.rank[i] = max(self.rank[i], self.rank[j] + 1) self.rank[i] self.rank self rank i max(self.rank[i], self.rank[j] + 1) max self.rank[i] self.rank self rank i self.rank[j] + 1 self.rank[j] self.rank self rank j 1 self.count[i] += self.count[j] self.count[i] self.count self count i self.count[j] self.count self count j self.parent[i] = j self.parent[i] self.parent self parent i j self.rank[j] = max(self.rank[j], self.rank[i] + 1) self.rank[j] self.rank self rank j max(self.rank[j], self.rank[i] + 1) max self.rank[j] self.rank self rank j self.rank[i] + 1 self.rank[i] self.rank self rank i 1 self.count[j] += self.count[i] self.count[j] self.count self count j self.count[i] self.count self count i self self i i j j int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n, m = [int(i) for i in input().split()] n [int(i) for i in input().split()] m uf = UnionFind(n) uf UnionFind(n) UnionFind n [int(i) - 1 for i in input().split()] for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) [int(i) - 1 for i in input().split()] ab = [[int(i) - 1 for i in input().split()] for _ in range(m)] ab [[int(i) - 1 for i in input().split()] for _ in range(m)] c = n * (n - 1) // 2 c n * (n - 1) // 2 n * (n - 1) n n - 1 n 1 2 ans = [] ans [] for a, b in reversed(ab):
    ans.append(c)
    if uf.is_same_tree(a, b):
        continue
    e = uf.get_root(a)
    f = uf.get_root(b)
    c -= uf.count[e] * uf.count[f]
    uf.merge(a, b) a b reversed(ab) reversed ab ans.append(c) ans.append ans append c if uf.is_same_tree(a, b):
        continue
     uf.is_same_tree(a, b) uf.is_same_tree uf is_same_tree a b continue e = uf.get_root(a) e uf.get_root(a) uf.get_root uf get_root a f = uf.get_root(b) f uf.get_root(b) uf.get_root uf get_root b c -= uf.count[e] * uf.count[f] c uf.count[e] * uf.count[f] uf.count[e] uf.count uf count e uf.count[f] uf.count uf count f uf.merge(a, b) uf.merge uf merge a b print("\n".join(map(str, reversed(ans)))) print "\n".join(map(str, reversed(ans))) "\n".join "\n" join map(str, reversed(ans)) map str reversed(ans) reversed ans n, m = [int(i) for i in input().split()] [int(i) for i in input().split()] n ab = [[int(i) - 1 for i in input().split()] for _ in range(m)] [[int(i) - 1 for i in input().split()] for _ in range(m)] ab c = n * (n - 1) // 2 n * (n - 1) // 2 c c -= uf.count[e] * uf.count[f] uf.count[e] * uf.count[f] c ans = [] [] ans f = uf.get_root(b) uf.get_root(b) f e = uf.get_root(a) uf.get_root(a) e uf = UnionFind(n) UnionFind(n) uf m = [int(i) for i in input().split()] [int(i) for i in input().split()] m class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n
        self.count = [1] * n

    def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

    def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

    def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i] class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n
        self.count = [1] * n

    def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

    def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

    def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i] UnionFind
class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n
        self.count = [1] * n

    def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

    def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

    def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i]


n, m = [int(i) for i in input().split()]
uf = UnionFind(n)
ab = [[int(i) - 1 for i in input().split()] for _ in range(m)]
c = n * (n - 1) // 2
ans = []
for a, b in reversed(ab):
    ans.append(c)
    if uf.is_same_tree(a, b):
        continue
    e = uf.get_root(a)
    f = uf.get_root(b)
    c -= uf.count[e] * uf.count[f]
    uf.merge(a, b)
print("\n".join(map(str, reversed(ans))))
