n, m = map(int, input().split())
# 逆順にunionfind
from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(lambda:1)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.weight[y] += self.weight[x]
            self.weight[x] = 0
        else:
            self.parent[y] = x
            self.weight[x] += self.weight[y]
            self.weight[y] = 0
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)

ps = []
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ps.append((a,b))

uf = UnionFind(n)
now = n*(n-1)//2
ans = [now]
for a, b in ps[::-1]:
    if not uf.judge(a,b):
        n1 = uf.weight[uf.find(a)]
        n2 = uf.weight[uf.find(b)]
        now += n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2
        uf.union(a,b)
    ans.append(now)

for a in ans[::-1][1:]:
    print(a) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m from collections import defaultdict class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(lambda:1)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.weight[y] += self.weight[x]
            self.weight[x] = 0
        else:
            self.parent[y] = x
            self.weight[x] += self.weight[y]
            self.weight[y] = 0
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y) UnionFind def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(lambda:1)

    # 根を探す
     __init__ class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
         KeyDict def __missing__(self,key):
                self[key] = key
                return key
         __missing__ self[key] = key self[key] self key key return key key self self key key dict self.parent = KeyDict() self.parent self parent KeyDict() KeyDict self.rank = defaultdict(int) self.rank self rank defaultdict(int) defaultdict int self.weight = defaultdict(lambda:1) self.weight self weight defaultdict(lambda:1) defaultdict lambda:1 1 self self n n def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
     find if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
     self.parent[x] == x self.parent[x] self.parent self parent x x return x x y = self.find(self.parent[x]) y self.find(self.parent[x]) self.find self find self.parent[x] self.parent self parent x self.parent[x] = y self.parent[x] self.parent self parent x y return self.parent[x] self.parent[x] self.parent self parent x self self x x def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.weight[y] += self.weight[x]
            self.weight[x] = 0
        else:
            self.parent[y] = x
            self.weight[x] += self.weight[y]
            self.weight[y] = 0
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


    # 判定
     union x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.weight[y] += self.weight[x]
            self.weight[x] = 0
        else:
            self.parent[y] = x
            self.weight[x] += self.weight[y]
            self.weight[y] = 0
        
         self.rank[x] < self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.parent[x] = y self.parent[x] self.parent self parent x y self.weight[y] += self.weight[x] self.weight[y] self.weight self weight y self.weight[x] self.weight self weight x self.weight[x] = 0 self.weight[x] self.weight self weight x 0 self.parent[y] = x self.parent[y] self.parent self parent y x self.weight[x] += self.weight[y] self.weight[x] self.weight self weight x self.weight[y] self.weight self weight y self.weight[y] = 0 self.weight[y] self.weight self weight y 0 if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


    # 判定
     self.rank[x] == self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.rank[x] += 1 self.rank[x] self.rank self rank x 1 self self x x y y def judge(self, x, y):
        return self.find(x) == self.find(y) judge return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y ps = [] ps [] for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ps.append((a,b)) i range(m) range m a,b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b a -= 1 a 1 b -= 1 b 1 ps.append((a,b)) ps.append ps append (a,b) a b uf = UnionFind(n) uf UnionFind(n) UnionFind n now = n*(n-1)//2 now n*(n-1)//2 n*(n-1) n n-1 n 1 2 ans = [now] ans [now] now for a, b in ps[::-1]:
    if not uf.judge(a,b):
        n1 = uf.weight[uf.find(a)]
        n2 = uf.weight[uf.find(b)]
        now += n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2
        uf.union(a,b)
    ans.append(now) a b ps[::-1] ps ::-1 -1 if not uf.judge(a,b):
        n1 = uf.weight[uf.find(a)]
        n2 = uf.weight[uf.find(b)]
        now += n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2
        uf.union(a,b)
     not uf.judge(a,b) uf.judge(a,b) uf.judge uf judge a b n1 = uf.weight[uf.find(a)] n1 uf.weight[uf.find(a)] uf.weight uf weight uf.find(a) uf.find uf find a n2 = uf.weight[uf.find(b)] n2 uf.weight[uf.find(b)] uf.weight uf weight uf.find(b) uf.find uf find b now += n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2 now n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2 n1*(n1-1)//2 + n2*(n2-1)//2 n1*(n1-1)//2 n1*(n1-1) n1 n1-1 n1 1 2 n2*(n2-1)//2 n2*(n2-1) n2 n2-1 n2 1 2 (n1+n2)*(n1+n2-1)//2 (n1+n2)*(n1+n2-1) n1+n2 n1 n2 n1+n2-1 n1+n2 n1 n2 1 2 uf.union(a,b) uf.union uf union a b ans.append(now) ans.append ans append now for a in ans[::-1][1:]:
    print(a) a ans[::-1][1:] [::-1] ans ::-1 -1 1: 1 print(a) print a b -= 1 1 b ps = [] [] ps n, m = map(int, input().split()) map(int, input().split()) n now += n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2 n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2 now n1 = uf.weight[uf.find(a)] uf.weight[uf.find(a)] n1 n2 = uf.weight[uf.find(b)] uf.weight[uf.find(b)] n2 a -= 1 1 a ans = [now] [now] ans m = map(int, input().split()) map(int, input().split()) m uf = UnionFind(n) UnionFind(n) uf a,b = map(int, input().split()) map(int, input().split()) a now = n*(n-1)//2 n*(n-1)//2 now class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(lambda:1)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.weight[y] += self.weight[x]
            self.weight[x] = 0
        else:
            self.parent[y] = x
            self.weight[x] += self.weight[y]
            self.weight[y] = 0
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y) class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(lambda:1)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.weight[y] += self.weight[x]
            self.weight[x] = 0
        else:
            self.parent[y] = x
            self.weight[x] += self.weight[y]
            self.weight[y] = 0
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y) UnionFind b = map(int, input().split()) map(int, input().split()) b
n, m = map(int, input().split())
# 逆順にunionfind
from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(lambda:1)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.weight[y] += self.weight[x]
            self.weight[x] = 0
        else:
            self.parent[y] = x
            self.weight[x] += self.weight[y]
            self.weight[y] = 0
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)

ps = []
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ps.append((a,b))

uf = UnionFind(n)
now = n*(n-1)//2
ans = [now]
for a, b in ps[::-1]:
    if not uf.judge(a,b):
        n1 = uf.weight[uf.find(a)]
        n2 = uf.weight[uf.find(b)]
        now += n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2
        uf.union(a,b)
    ans.append(now)

for a in ans[::-1][1:]:
    print(a)