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

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.n-=1
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
        else:
            self.n-=1
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

    def same(self, x, y):
        return self.find(x)==self.find(y)

    def count(self, x):
        return -self.root[self.find(x)-1]

    def size(self):
        return self.n

N,M=map(int,input().split())
B=[tuple(map(int,input().split())) for i in range(M)]
s=N*(N-1)//2
ans=[0]*M
uf=UnionFind(N)
for i in range(M-1,-1,-1):
    ans[i]=s
    a,b=B[i]
    if uf.find(a)!=uf.find(b):
        t1,t2=uf.count(a),uf.count(b)
        uf.unite(a,b)
        s-=(t1+t2)*(t1+t2-1)//2-(t1*(t1-1)//2+t2*(t2-1)//2)
print(*ans,sep='\n') class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*n
        self.rank = [0]*n

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.n-=1
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
        else:
            self.n-=1
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

    def same(self, x, y):
        return self.find(x)==self.find(y)

    def count(self, x):
        return -self.root[self.find(x)-1]

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

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

     find if self.root[x-1] < 0:
            return x
        else:
            self.root[x-1] = self.find(self.root[x-1])
            return self.root[x-1]

     self.root[x-1] < 0 self.root[x-1] self.root self root x-1 x 1 0 return x x self.root[x-1] = self.find(self.root[x-1]) self.root[x-1] self.root self root x-1 x 1 self.find(self.root[x-1]) self.find self find self.root[x-1] self.root self root x-1 x 1 return self.root[x-1] self.root[x-1] self.root self root x-1 x 1 self self x x def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.n-=1
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
        else:
            self.n-=1
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

     unite 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 x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.n-=1
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
        else:
            self.n-=1
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

     x==y x y return elif self.rank[x-1] > self.rank[y-1]:
            self.n-=1
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
         self.rank[x-1] > self.rank[y-1] self.rank[x-1] self.rank self rank x-1 x 1 self.rank[y-1] self.rank self rank y-1 y 1 self.n-=1 self.n self n 1 self.root[x-1] += self.root[y-1] self.root[x-1] self.root self root x-1 x 1 self.root[y-1] self.root self root y-1 y 1 self.root[y-1] = x self.root[y-1] self.root self root y-1 y 1 x self.n-=1 self.n self n 1 self.root[y-1] += self.root[x-1] self.root[y-1] self.root self root y-1 y 1 self.root[x-1] self.root self root x-1 x 1 self.root[x-1] = y self.root[x-1] self.root self root x-1 x 1 y if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

     self.rank[x-1] == self.rank[y-1] self.rank[x-1] self.rank self rank x-1 x 1 self.rank[y-1] self.rank self rank y-1 y 1 self.rank[y-1] += 1 self.rank[y-1] self.rank self rank y-1 y 1 1 self self x x y y def same(self, x, y):
        return self.find(x)==self.find(y)

     same 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 def count(self, x):
        return -self.root[self.find(x)-1]

     count return -self.root[self.find(x)-1] -self.root[self.find(x)-1] self.root[self.find(x)-1] self.root self root self.find(x)-1 self.find(x) self.find self find x 1 self self x x def size(self):
        return self.n size return self.n self.n self n self self N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M tuple(map(int,input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split B=[tuple(map(int,input().split())) for i in range(M)] B [tuple(map(int,input().split())) for i in range(M)] s=N*(N-1)//2 s N*(N-1)//2 N*(N-1) N N-1 N 1 2 ans=[0]*M ans [0]*M [0] 0 M uf=UnionFind(N) uf UnionFind(N) UnionFind N for i in range(M-1,-1,-1):
    ans[i]=s
    a,b=B[i]
    if uf.find(a)!=uf.find(b):
        t1,t2=uf.count(a),uf.count(b)
        uf.unite(a,b)
        s-=(t1+t2)*(t1+t2-1)//2-(t1*(t1-1)//2+t2*(t2-1)//2) i range(M-1,-1,-1) range M-1 M 1 -1 -1 ans[i]=s ans[i] ans i s a,b=B[i] a B[i] B i b if uf.find(a)!=uf.find(b):
        t1,t2=uf.count(a),uf.count(b)
        uf.unite(a,b)
        s-=(t1+t2)*(t1+t2-1)//2-(t1*(t1-1)//2+t2*(t2-1)//2) uf.find(a)!=uf.find(b) uf.find(a) uf.find uf find a uf.find(b) uf.find uf find b t1,t2=uf.count(a),uf.count(b) t1 uf.count(a) uf.count uf count a t2 uf.count(b) uf.count uf count b uf.unite(a,b) uf.unite uf unite a b s-=(t1+t2)*(t1+t2-1)//2-(t1*(t1-1)//2+t2*(t2-1)//2) s (t1+t2)*(t1+t2-1)//2-(t1*(t1-1)//2+t2*(t2-1)//2) (t1+t2)*(t1+t2-1)//2 (t1+t2)*(t1+t2-1) t1+t2 t1 t2 t1+t2-1 t1+t2 t1 t2 1 2 t1*(t1-1)//2+t2*(t2-1)//2 t1*(t1-1)//2 t1*(t1-1) t1 t1-1 t1 1 2 t2*(t2-1)//2 t2*(t2-1) t2 t2-1 t2 1 2 print(*ans,sep='\n') print *ans ans sep='\n' sep '\n' class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*n
        self.rank = [0]*n

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.n-=1
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
        else:
            self.n-=1
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

    def same(self, x, y):
        return self.find(x)==self.find(y)

    def count(self, x):
        return -self.root[self.find(x)-1]

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

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.n-=1
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
        else:
            self.n-=1
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

    def same(self, x, y):
        return self.find(x)==self.find(y)

    def count(self, x):
        return -self.root[self.find(x)-1]

    def size(self):
        return self.n UnionFind N,M=map(int,input().split()) map(int,input().split()) N t1,t2=uf.count(a),uf.count(b) uf.count(a) t1 ans=[0]*M [0]*M ans a,b=B[i] B[i] a s-=(t1+t2)*(t1+t2-1)//2-(t1*(t1-1)//2+t2*(t2-1)//2) (t1+t2)*(t1+t2-1)//2-(t1*(t1-1)//2+t2*(t2-1)//2) s M=map(int,input().split()) map(int,input().split()) M b=B[i] B[i] b B=[tuple(map(int,input().split())) for i in range(M)] [tuple(map(int,input().split())) for i in range(M)] B t2=uf.count(a),uf.count(b) uf.count(b) t2 s=N*(N-1)//2 N*(N-1)//2 s uf=UnionFind(N) UnionFind(N) uf
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*n
        self.rank = [0]*n

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.n-=1
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
        else:
            self.n-=1
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

    def same(self, x, y):
        return self.find(x)==self.find(y)

    def count(self, x):
        return -self.root[self.find(x)-1]

    def size(self):
        return self.n

N,M=map(int,input().split())
B=[tuple(map(int,input().split())) for i in range(M)]
s=N*(N-1)//2
ans=[0]*M
uf=UnionFind(N)
for i in range(M-1,-1,-1):
    ans[i]=s
    a,b=B[i]
    if uf.find(a)!=uf.find(b):
        t1,t2=uf.count(a),uf.count(b)
        uf.unite(a,b)
        s-=(t1+t2)*(t1+t2-1)//2-(t1*(t1-1)//2+t2*(t2-1)//2)
print(*ans,sep='\n')