#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    class UnionFindTree:
        def __init__(self, num_of_elm):
            self.n = num_of_elm
            self.table = [i for i in range(self.n)]
            self.rank = [0] * self.n
            self.group_size = [1] * self.n
            self.roots = set(i for i in range(self.n))
        
        def _find_set(self, x):
            '''
            x の属するグループ番号を O(α(n)) で求める
            '''
            parent = self.table[x]
            if x == parent:
                return x
            else:
                root = self._find_set(parent)
                # 経路圧縮
                self.table[x] = root
                return root
        
        def is_same(self, x, y):
            '''
            x と y が同じグループに属するか O(α(n)) で判定する
            '''
            return self._find_set(x) == self._find_set(y)
    
        def union(self, x, y):
            '''
            x と y の属するグループを O(α(n)) で統合する
            '''
            shallow_root = self._find_set(x)
            deep_root = self._find_set(y)
            if self.rank[shallow_root] > self.rank[deep_root]:
                shallow_root, deep_root = deep_root, shallow_root
            # そもそも同一グループだった時
            if shallow_root == deep_root:
                return False
            # グループが異なるので union
            else:
                self.roots.remove(shallow_root)
                self.table[shallow_root] = deep_root
                self.group_size[deep_root] += self.group_size[shallow_root]
                # 深さが等しかったときはつけ加えられた側の rank をインクリメントする
                if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                return True
    
        def akin_num(self, x):
            '''
            x の属するグループのサイズを O(1) で計算する
            '''
            x_root = self._find_set(x)
            return self.group_size[x_root]
    
        def print_group_id(self):
            print([self._find_set(x) for x in self.table])


    n, m = mi()
    query = [lmi_0() for _ in range(m)]
    query.reverse()

    ans = []
    total_pairs = n * (n - 1) // 2
    connected_pairs = 0
    uf = UnionFindTree(n)
    for i in range(m):
        ans.append(total_pairs - connected_pairs)
        group_a_size = uf.akin_num(query[i][0])
        group_b_size = uf.akin_num(query[i][1])
        result = uf.union(query[i][0], query[i][1])
        if result:
            # 異なるグループがマージされた
            connected_pairs += group_a_size * group_b_size
    
    for elm in reversed(ans):
        print(elm)




if __name__ == "__main__":
    main() import sys sys def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    class UnionFindTree:
        def __init__(self, num_of_elm):
            self.n = num_of_elm
            self.table = [i for i in range(self.n)]
            self.rank = [0] * self.n
            self.group_size = [1] * self.n
            self.roots = set(i for i in range(self.n))
        
        def _find_set(self, x):
            '''
            x の属するグループ番号を O(α(n)) で求める
            '''
            parent = self.table[x]
            if x == parent:
                return x
            else:
                root = self._find_set(parent)
                # 経路圧縮
                self.table[x] = root
                return root
        
        def is_same(self, x, y):
            '''
            x と y が同じグループに属するか O(α(n)) で判定する
            '''
            return self._find_set(x) == self._find_set(y)
    
        def union(self, x, y):
            '''
            x と y の属するグループを O(α(n)) で統合する
            '''
            shallow_root = self._find_set(x)
            deep_root = self._find_set(y)
            if self.rank[shallow_root] > self.rank[deep_root]:
                shallow_root, deep_root = deep_root, shallow_root
            # そもそも同一グループだった時
            if shallow_root == deep_root:
                return False
            # グループが異なるので union
            else:
                self.roots.remove(shallow_root)
                self.table[shallow_root] = deep_root
                self.group_size[deep_root] += self.group_size[shallow_root]
                # 深さが等しかったときはつけ加えられた側の rank をインクリメントする
                if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                return True
    
        def akin_num(self, x):
            '''
            x の属するグループのサイズを O(1) で計算する
            '''
            x_root = self._find_set(x)
            return self.group_size[x_root]
    
        def print_group_id(self):
            print([self._find_set(x) for x in self.table])


    n, m = mi()
    query = [lmi_0() for _ in range(m)]
    query.reverse()

    ans = []
    total_pairs = n * (n - 1) // 2
    connected_pairs = 0
    uf = UnionFindTree(n)
    for i in range(m):
        ans.append(total_pairs - connected_pairs)
        group_a_size = uf.akin_num(query[i][0])
        group_b_size = uf.akin_num(query[i][1])
        result = uf.union(query[i][0], query[i][1])
        if result:
            # 異なるグループがマージされた
            connected_pairs += group_a_size * group_b_size
    
    for elm in reversed(ans):
        print(elm) main mod = 1000000007 mod 1000000007 inf = float('inf') inf float('inf') float 'inf' sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 def input(): return sys.stdin.readline().rstrip()
     input def ii():    return int(input())
     ii def mi():    return map(int, input().split())
     mi def mi_0():  return map(lambda x: int(x)-1, input().split())
     mi_0 def lmi():   return list(map(int, input().split()))
     lmi def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
     lmi_0 def li():    return list(input())
    
    
     li class UnionFindTree:
        def __init__(self, num_of_elm):
            self.n = num_of_elm
            self.table = [i for i in range(self.n)]
            self.rank = [0] * self.n
            self.group_size = [1] * self.n
            self.roots = set(i for i in range(self.n))
        
        def _find_set(self, x):
            '''
            x の属するグループ番号を O(α(n)) で求める
            '''
            parent = self.table[x]
            if x == parent:
                return x
            else:
                root = self._find_set(parent)
                # 経路圧縮
                self.table[x] = root
                return root
        
        def is_same(self, x, y):
            '''
            x と y が同じグループに属するか O(α(n)) で判定する
            '''
            return self._find_set(x) == self._find_set(y)
    
        def union(self, x, y):
            '''
            x と y の属するグループを O(α(n)) で統合する
            '''
            shallow_root = self._find_set(x)
            deep_root = self._find_set(y)
            if self.rank[shallow_root] > self.rank[deep_root]:
                shallow_root, deep_root = deep_root, shallow_root
            # そもそも同一グループだった時
            if shallow_root == deep_root:
                return False
            # グループが異なるので union
            else:
                self.roots.remove(shallow_root)
                self.table[shallow_root] = deep_root
                self.group_size[deep_root] += self.group_size[shallow_root]
                # 深さが等しかったときはつけ加えられた側の rank をインクリメントする
                if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                return True
    
        def akin_num(self, x):
            '''
            x の属するグループのサイズを O(1) で計算する
            '''
            x_root = self._find_set(x)
            return self.group_size[x_root]
    
        def print_group_id(self):
            print([self._find_set(x) for x in self.table])


     UnionFindTree def __init__(self, num_of_elm):
            self.n = num_of_elm
            self.table = [i for i in range(self.n)]
            self.rank = [0] * self.n
            self.group_size = [1] * self.n
            self.roots = set(i for i in range(self.n))
        
         __init__ self.n = num_of_elm self.n self n num_of_elm i for i in range(self.n) for i in range(self.n) i range(self.n) range self.n self n for i in range(self.n) i self.table = [i for i in range(self.n)] self.table self table [i for i in range(self.n)] self.rank = [0] * self.n self.rank self rank [0] * self.n [0] 0 self.n self n self.group_size = [1] * self.n self.group_size self group_size [1] * self.n [1] 1 self.n self n self.roots = set(i for i in range(self.n)) self.roots self roots set(i for i in range(self.n)) set i self self num_of_elm num_of_elm def _find_set(self, x):
            '''
            x の属するグループ番号を O(α(n)) で求める
            '''
            parent = self.table[x]
            if x == parent:
                return x
            else:
                root = self._find_set(parent)
                # 経路圧縮
                self.table[x] = root
                return root
        
         _find_set '''
            x の属するグループ番号を O(α(n)) で求める
            ''' parent = self.table[x] parent self.table[x] self.table self table x if x == parent:
                return x
            else:
                root = self._find_set(parent)
                # 経路圧縮
                self.table[x] = root
                return root
        
         x == parent x parent return x x root = self._find_set(parent) root self._find_set(parent) self._find_set self _find_set parent self.table[x] = root self.table[x] self.table self table x root return root root self self x x def is_same(self, x, y):
            '''
            x と y が同じグループに属するか O(α(n)) で判定する
            '''
            return self._find_set(x) == self._find_set(y)
    
         is_same '''
            x と y が同じグループに属するか O(α(n)) で判定する
            ''' return self._find_set(x) == self._find_set(y) self._find_set(x) == self._find_set(y) self._find_set(x) self._find_set self _find_set x self._find_set(y) self._find_set self _find_set y self self x x y y def union(self, x, y):
            '''
            x と y の属するグループを O(α(n)) で統合する
            '''
            shallow_root = self._find_set(x)
            deep_root = self._find_set(y)
            if self.rank[shallow_root] > self.rank[deep_root]:
                shallow_root, deep_root = deep_root, shallow_root
            # そもそも同一グループだった時
            if shallow_root == deep_root:
                return False
            # グループが異なるので union
            else:
                self.roots.remove(shallow_root)
                self.table[shallow_root] = deep_root
                self.group_size[deep_root] += self.group_size[shallow_root]
                # 深さが等しかったときはつけ加えられた側の rank をインクリメントする
                if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                return True
    
         union '''
            x と y の属するグループを O(α(n)) で統合する
            ''' shallow_root = self._find_set(x) shallow_root self._find_set(x) self._find_set self _find_set x deep_root = self._find_set(y) deep_root self._find_set(y) self._find_set self _find_set y if self.rank[shallow_root] > self.rank[deep_root]:
                shallow_root, deep_root = deep_root, shallow_root
            # そもそも同一グループだった時
             self.rank[shallow_root] > self.rank[deep_root] self.rank[shallow_root] self.rank self rank shallow_root self.rank[deep_root] self.rank self rank deep_root shallow_root, deep_root = deep_root, shallow_root shallow_root deep_root deep_root shallow_root if shallow_root == deep_root:
                return False
            # グループが異なるので union
            else:
                self.roots.remove(shallow_root)
                self.table[shallow_root] = deep_root
                self.group_size[deep_root] += self.group_size[shallow_root]
                # 深さが等しかったときはつけ加えられた側の rank をインクリメントする
                if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                return True
    
         shallow_root == deep_root shallow_root deep_root return False False self.roots.remove(shallow_root) self.roots.remove self.roots self roots remove shallow_root self.table[shallow_root] = deep_root self.table[shallow_root] self.table self table shallow_root deep_root self.group_size[deep_root] += self.group_size[shallow_root] self.group_size[deep_root] self.group_size self group_size deep_root self.group_size[shallow_root] self.group_size self group_size shallow_root if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                 self.rank[shallow_root] == self.rank[deep_root] self.rank[shallow_root] self.rank self rank shallow_root self.rank[deep_root] self.rank self rank deep_root self.rank[deep_root] += 1 self.rank[deep_root] self.rank self rank deep_root 1 return True True self self x x y y def akin_num(self, x):
            '''
            x の属するグループのサイズを O(1) で計算する
            '''
            x_root = self._find_set(x)
            return self.group_size[x_root]
    
         akin_num '''
            x の属するグループのサイズを O(1) で計算する
            ''' x_root = self._find_set(x) x_root self._find_set(x) self._find_set self _find_set x return self.group_size[x_root] self.group_size[x_root] self.group_size self group_size x_root self self x x def print_group_id(self):
            print([self._find_set(x) for x in self.table])


     print_group_id self._find_set(x) for x in self.table for x in self.table x self.table self table for x in self.table self._find_set(x) self._find_set self _find_set x print([self._find_set(x) for x in self.table]) print [self._find_set(x) for x in self.table] self self n, m = mi() n mi() mi m lmi_0() for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) lmi_0() lmi_0 query = [lmi_0() for _ in range(m)] query [lmi_0() for _ in range(m)] query.reverse() query.reverse query reverse ans = [] ans [] total_pairs = n * (n - 1) // 2 total_pairs n * (n - 1) // 2 n * (n - 1) n n - 1 n 1 2 connected_pairs = 0 connected_pairs 0 uf = UnionFindTree(n) uf UnionFindTree(n) UnionFindTree n for i in range(m):
        ans.append(total_pairs - connected_pairs)
        group_a_size = uf.akin_num(query[i][0])
        group_b_size = uf.akin_num(query[i][1])
        result = uf.union(query[i][0], query[i][1])
        if result:
            # 異なるグループがマージされた
            connected_pairs += group_a_size * group_b_size
    
     i range(m) range m ans.append(total_pairs - connected_pairs) ans.append ans append total_pairs - connected_pairs total_pairs connected_pairs group_a_size = uf.akin_num(query[i][0]) group_a_size uf.akin_num(query[i][0]) uf.akin_num uf akin_num query[i][0] [i] query i 0 group_b_size = uf.akin_num(query[i][1]) group_b_size uf.akin_num(query[i][1]) uf.akin_num uf akin_num query[i][1] [i] query i 1 result = uf.union(query[i][0], query[i][1]) result uf.union(query[i][0], query[i][1]) uf.union uf union query[i][0] [i] query i 0 query[i][1] [i] query i 1 if result:
            # 異なるグループがマージされた
            connected_pairs += group_a_size * group_b_size
    
     result connected_pairs += group_a_size * group_b_size connected_pairs group_a_size * group_b_size group_a_size group_b_size for elm in reversed(ans):
        print(elm) elm reversed(ans) reversed ans print(elm) print elm if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    class UnionFindTree:
        def __init__(self, num_of_elm):
            self.n = num_of_elm
            self.table = [i for i in range(self.n)]
            self.rank = [0] * self.n
            self.group_size = [1] * self.n
            self.roots = set(i for i in range(self.n))
        
        def _find_set(self, x):
            '''
            x の属するグループ番号を O(α(n)) で求める
            '''
            parent = self.table[x]
            if x == parent:
                return x
            else:
                root = self._find_set(parent)
                # 経路圧縮
                self.table[x] = root
                return root
        
        def is_same(self, x, y):
            '''
            x と y が同じグループに属するか O(α(n)) で判定する
            '''
            return self._find_set(x) == self._find_set(y)
    
        def union(self, x, y):
            '''
            x と y の属するグループを O(α(n)) で統合する
            '''
            shallow_root = self._find_set(x)
            deep_root = self._find_set(y)
            if self.rank[shallow_root] > self.rank[deep_root]:
                shallow_root, deep_root = deep_root, shallow_root
            # そもそも同一グループだった時
            if shallow_root == deep_root:
                return False
            # グループが異なるので union
            else:
                self.roots.remove(shallow_root)
                self.table[shallow_root] = deep_root
                self.group_size[deep_root] += self.group_size[shallow_root]
                # 深さが等しかったときはつけ加えられた側の rank をインクリメントする
                if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                return True
    
        def akin_num(self, x):
            '''
            x の属するグループのサイズを O(1) で計算する
            '''
            x_root = self._find_set(x)
            return self.group_size[x_root]
    
        def print_group_id(self):
            print([self._find_set(x) for x in self.table])


    n, m = mi()
    query = [lmi_0() for _ in range(m)]
    query.reverse()

    ans = []
    total_pairs = n * (n - 1) // 2
    connected_pairs = 0
    uf = UnionFindTree(n)
    for i in range(m):
        ans.append(total_pairs - connected_pairs)
        group_a_size = uf.akin_num(query[i][0])
        group_b_size = uf.akin_num(query[i][1])
        result = uf.union(query[i][0], query[i][1])
        if result:
            # 異なるグループがマージされた
            connected_pairs += group_a_size * group_b_size
    
    for elm in reversed(ans):
        print(elm) def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    class UnionFindTree:
        def __init__(self, num_of_elm):
            self.n = num_of_elm
            self.table = [i for i in range(self.n)]
            self.rank = [0] * self.n
            self.group_size = [1] * self.n
            self.roots = set(i for i in range(self.n))
        
        def _find_set(self, x):
            '''
            x の属するグループ番号を O(α(n)) で求める
            '''
            parent = self.table[x]
            if x == parent:
                return x
            else:
                root = self._find_set(parent)
                # 経路圧縮
                self.table[x] = root
                return root
        
        def is_same(self, x, y):
            '''
            x と y が同じグループに属するか O(α(n)) で判定する
            '''
            return self._find_set(x) == self._find_set(y)
    
        def union(self, x, y):
            '''
            x と y の属するグループを O(α(n)) で統合する
            '''
            shallow_root = self._find_set(x)
            deep_root = self._find_set(y)
            if self.rank[shallow_root] > self.rank[deep_root]:
                shallow_root, deep_root = deep_root, shallow_root
            # そもそも同一グループだった時
            if shallow_root == deep_root:
                return False
            # グループが異なるので union
            else:
                self.roots.remove(shallow_root)
                self.table[shallow_root] = deep_root
                self.group_size[deep_root] += self.group_size[shallow_root]
                # 深さが等しかったときはつけ加えられた側の rank をインクリメントする
                if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                return True
    
        def akin_num(self, x):
            '''
            x の属するグループのサイズを O(1) で計算する
            '''
            x_root = self._find_set(x)
            return self.group_size[x_root]
    
        def print_group_id(self):
            print([self._find_set(x) for x in self.table])


    n, m = mi()
    query = [lmi_0() for _ in range(m)]
    query.reverse()

    ans = []
    total_pairs = n * (n - 1) // 2
    connected_pairs = 0
    uf = UnionFindTree(n)
    for i in range(m):
        ans.append(total_pairs - connected_pairs)
        group_a_size = uf.akin_num(query[i][0])
        group_b_size = uf.akin_num(query[i][1])
        result = uf.union(query[i][0], query[i][1])
        if result:
            # 異なるグループがマージされた
            connected_pairs += group_a_size * group_b_size
    
    for elm in reversed(ans):
        print(elm) main
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    class UnionFindTree:
        def __init__(self, num_of_elm):
            self.n = num_of_elm
            self.table = [i for i in range(self.n)]
            self.rank = [0] * self.n
            self.group_size = [1] * self.n
            self.roots = set(i for i in range(self.n))
        
        def _find_set(self, x):
            '''
            x の属するグループ番号を O(α(n)) で求める
            '''
            parent = self.table[x]
            if x == parent:
                return x
            else:
                root = self._find_set(parent)
                # 経路圧縮
                self.table[x] = root
                return root
        
        def is_same(self, x, y):
            '''
            x と y が同じグループに属するか O(α(n)) で判定する
            '''
            return self._find_set(x) == self._find_set(y)
    
        def union(self, x, y):
            '''
            x と y の属するグループを O(α(n)) で統合する
            '''
            shallow_root = self._find_set(x)
            deep_root = self._find_set(y)
            if self.rank[shallow_root] > self.rank[deep_root]:
                shallow_root, deep_root = deep_root, shallow_root
            # そもそも同一グループだった時
            if shallow_root == deep_root:
                return False
            # グループが異なるので union
            else:
                self.roots.remove(shallow_root)
                self.table[shallow_root] = deep_root
                self.group_size[deep_root] += self.group_size[shallow_root]
                # 深さが等しかったときはつけ加えられた側の rank をインクリメントする
                if self.rank[shallow_root] == self.rank[deep_root]:
                    self.rank[deep_root] += 1
                return True
    
        def akin_num(self, x):
            '''
            x の属するグループのサイズを O(1) で計算する
            '''
            x_root = self._find_set(x)
            return self.group_size[x_root]
    
        def print_group_id(self):
            print([self._find_set(x) for x in self.table])


    n, m = mi()
    query = [lmi_0() for _ in range(m)]
    query.reverse()

    ans = []
    total_pairs = n * (n - 1) // 2
    connected_pairs = 0
    uf = UnionFindTree(n)
    for i in range(m):
        ans.append(total_pairs - connected_pairs)
        group_a_size = uf.akin_num(query[i][0])
        group_b_size = uf.akin_num(query[i][1])
        result = uf.union(query[i][0], query[i][1])
        if result:
            # 異なるグループがマージされた
            connected_pairs += group_a_size * group_b_size
    
    for elm in reversed(ans):
        print(elm)




if __name__ == "__main__":
    main()
