import sys
sys.setrecursionlimit(10**9)
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]


def main():
    n,m = tuple([int(t)for t in input().split()])

    bridge = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m]
    bridge = bridge[::-1]

    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for a_i,b_i in bridge:
        if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
    ans.pop()
    for a in ans[::-1]:
        print(a)



if __name__ == "__main__":
    main() import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)] UnionFind def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
     __init__ super().__init__() ().__init__ () super __init__ self.par = [-1]*n self.par self par [-1]*n [-1] -1 n self.rank = [0]*n self.rank self rank [0]*n [0] 0 n self.tsize = [1]*n self.tsize self tsize [1]*n [1] 1 n self self n n def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

     root if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

     self.par[x] == -1 self.par[x] self.par self par x -1 return x x self.par[x] = self.root(self.par[x]) self.par[x] self.par self par x self.root(self.par[x]) self.root self root self.par[x] self.par self par x return self.par[x] self.par[x] self.par self par x self self x x def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

     unite x_r = self.root(x) x_r self.root(x) self.root self root x y_r = self.root(y) y_r self.root(y) self.root self root y if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

         self.rank[x_r]>self.rank[y_r] self.rank[x_r] self.rank self rank x_r self.rank[y_r] self.rank self rank y_r self.par[y_r] = x_r self.par[y_r] self.par self par y_r x_r elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

         self.rank[x_r]<self.rank[y_r] self.rank[x_r] self.rank self rank x_r self.rank[y_r] self.rank self rank y_r self.par[x_r] = y_r self.par[x_r] self.par self par x_r y_r elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

         x_r != y_r x_r y_r self.par[y_r] = x_r self.par[y_r] self.par self par y_r x_r self.rank[x_r] += 1 self.rank[x_r] self.rank self rank x_r 1 if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

     x_r != y_r x_r y_r size = self.tsize[x_r]+self.tsize[y_r] size self.tsize[x_r]+self.tsize[y_r] self.tsize[x_r] self.tsize self tsize x_r self.tsize[y_r] self.tsize self tsize y_r self.tsize[x_r] = size self.tsize[x_r] self.tsize self tsize x_r size self.tsize[y_r] = size self.tsize[y_r] self.tsize self tsize y_r size self self x x y y def isSame(self,x,y):
        return self.root(x) == self.root(y)

     isSame return self.root(x) == self.root(y) self.root(x) == self.root(y) self.root(x) self.root self root x self.root(y) self.root self root y self self x x y y def size(self,x):
        return self.tsize[self.root(x)] size return self.tsize[self.root(x)] self.tsize[self.root(x)] self.tsize self tsize self.root(x) self.root self root x self self x x def main():
    n,m = tuple([int(t)for t in input().split()])

    bridge = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m]
    bridge = bridge[::-1]

    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for a_i,b_i in bridge:
        if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
    ans.pop()
    for a in ans[::-1]:
        print(a) main int(t)for t in input().split() for t in input().split() t input().split() ().split () input split for t in input().split() int(t) int t n,m = tuple([int(t)for t in input().split()]) n tuple([int(t)for t in input().split()]) tuple [int(t)for t in input().split()] m tuple([int(t)-1 for t in input().split()])for _ in [0]*m for _ in [0]*m _ [0]*m [0] 0 m for _ in [0]*m tuple([int(t)-1 for t in input().split()]) tuple [int(t)-1 for t in input().split()] bridge = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m] bridge [tuple([int(t)-1 for t in input().split()])for _ in [0]*m] bridge = bridge[::-1] bridge bridge[::-1] bridge ::-1 -1 uf = UnionFind(n) uf UnionFind(n) UnionFind n ans = [n*(n-1)//2] ans [n*(n-1)//2] n*(n-1)//2 n*(n-1) n n-1 n 1 2 for a_i,b_i in bridge:
        if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
     a_i b_i bridge if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
     not uf.isSame(a_i,b_i) uf.isSame(a_i,b_i) uf.isSame uf isSame a_i b_i ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i)) ans.append ans append ans[-1]-uf.size(a_i)*uf.size(b_i) ans[-1] ans -1 uf.size(a_i)*uf.size(b_i) uf.size(a_i) uf.size uf size a_i uf.size(b_i) uf.size uf size b_i uf.unite(a_i,b_i) uf.unite uf unite a_i b_i ans.append(ans[-1]) ans.append ans append ans[-1] ans -1 ans.pop() ans.pop ans pop for a in ans[::-1]:
        print(a) a ans[::-1] ans ::-1 -1 print(a) print a if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n,m = tuple([int(t)for t in input().split()])

    bridge = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m]
    bridge = bridge[::-1]

    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for a_i,b_i in bridge:
        if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
    ans.pop()
    for a in ans[::-1]:
        print(a) def main():
    n,m = tuple([int(t)for t in input().split()])

    bridge = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m]
    bridge = bridge[::-1]

    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for a_i,b_i in bridge:
        if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
    ans.pop()
    for a in ans[::-1]:
        print(a) main class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)] class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)] UnionFind
import sys
sys.setrecursionlimit(10**9)
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]


def main():
    n,m = tuple([int(t)for t in input().split()])

    bridge = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m]
    bridge = bridge[::-1]

    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for a_i,b_i in bridge:
        if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
    ans.pop()
    for a in ans[::-1]:
        print(a)



if __name__ == "__main__":
    main()