#時系列の逆順で見る
def root(x):
    if p[x]==x:
        return x
    p[x] = y = root(p[x])
    return y
def union(x,y):
    px = root(x); py = root(y)
    if px == py:
        return
    if r[px]>r[py]:
        p[py]=px
    else:
        p[px]=py
        if r[py]==r[px]:
            r[py]+=1
def same(x,y):
    px = root(x)
    py = root(y)
    if px==py:
        return True
    else:
        return False
n,m = map(int, input().split( ))

e = []

for i in range(m):
    a,b = map(int, input().split( ))
    e.append((a,b))

e.reverse()
p = [i for i in range(n+1)]
r = [0 for i in range(n+1)]
c = [1 for i in range(n+1)]

cnt = 0
ans=[]
for i in range(m-1):
    x,y = e[i]
    if same(x,y):
        ans.append(n*(n-1)//2-cnt)
    else:
        cx = c[root(x)];cy=c[root(y)]
        union(x,y)
        cnt += (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 - cy*(cy-1)//2
        c[root(x)] = 0; c[root(y)]=0
        c[root(x)] = cx+cy
        ans.append(n*(n-1)//2-cnt)
ans.reverse()
for ai in ans:
    print(ai)
print(n*(n-1)//2)
    
     def root(x):
    if p[x]==x:
        return x
    p[x] = y = root(p[x])
    return y root if p[x]==x:
        return x
     p[x]==x p[x] p x x return x x p[x] = y = root(p[x]) p[x] p x root(p[x]) root p[x] p x = y = root(p[x]) y root(p[x]) return y y x x def union(x,y):
    px = root(x); py = root(y)
    if px == py:
        return
    if r[px]>r[py]:
        p[py]=px
    else:
        p[px]=py
        if r[py]==r[px]:
            r[py]+=1 union px = root(x) px root(x) root x py = root(y) py root(y) root y if px == py:
        return
     px == py px py return if r[px]>r[py]:
        p[py]=px
    else:
        p[px]=py
        if r[py]==r[px]:
            r[py]+=1 r[px]>r[py] r[px] r px r[py] r py p[py]=px p[py] p py px p[px]=py p[px] p px py if r[py]==r[px]:
            r[py]+=1 r[py]==r[px] r[py] r py r[px] r px r[py]+=1 r[py] r py 1 x x y y def same(x,y):
    px = root(x)
    py = root(y)
    if px==py:
        return True
    else:
        return False same px = root(x) px root(x) root x py = root(y) py root(y) root y if px==py:
        return True
    else:
        return False px==py px py return True True return False False x x y y n,m = map(int, input().split( )) n map(int, input().split( )) map int input().split( ) ().split () input split m e = [] e [] for i in range(m):
    a,b = map(int, input().split( ))
    e.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 e.append((a,b)) e.append e append (a,b) a b e.reverse() e.reverse e reverse i for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) i p = [i for i in range(n+1)] p [i for i in range(n+1)] 0 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) 0 r = [0 for i in range(n+1)] r [0 for i in range(n+1)] 1 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) 1 c = [1 for i in range(n+1)] c [1 for i in range(n+1)] cnt = 0 cnt 0 ans=[] ans [] for i in range(m-1):
    x,y = e[i]
    if same(x,y):
        ans.append(n*(n-1)//2-cnt)
    else:
        cx = c[root(x)];cy=c[root(y)]
        union(x,y)
        cnt += (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 - cy*(cy-1)//2
        c[root(x)] = 0; c[root(y)]=0
        c[root(x)] = cx+cy
        ans.append(n*(n-1)//2-cnt) i range(m-1) range m-1 m 1 x,y = e[i] x e[i] e i y if same(x,y):
        ans.append(n*(n-1)//2-cnt)
    else:
        cx = c[root(x)];cy=c[root(y)]
        union(x,y)
        cnt += (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 - cy*(cy-1)//2
        c[root(x)] = 0; c[root(y)]=0
        c[root(x)] = cx+cy
        ans.append(n*(n-1)//2-cnt) same(x,y) same x y ans.append(n*(n-1)//2-cnt) ans.append ans append n*(n-1)//2-cnt n*(n-1)//2 n*(n-1) n n-1 n 1 2 cnt cx = c[root(x)] cx c[root(x)] c root(x) root x cy=c[root(y)] cy c[root(y)] c root(y) root y union(x,y) union x y cnt += (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 - cy*(cy-1)//2 cnt (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 - cy*(cy-1)//2 (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 (cx+cy)*(cx+cy-1)//2 (cx+cy)*(cx+cy-1) cx+cy cx cy cx+cy-1 cx+cy cx cy 1 2 cx*(cx-1)//2 cx*(cx-1) cx cx-1 cx 1 2 cy*(cy-1)//2 cy*(cy-1) cy cy-1 cy 1 2 c[root(x)] = 0 c[root(x)] c root(x) root x 0 c[root(y)]=0 c[root(y)] c root(y) root y 0 c[root(x)] = cx+cy c[root(x)] c root(x) root x cx+cy cx cy ans.append(n*(n-1)//2-cnt) ans.append ans append n*(n-1)//2-cnt n*(n-1)//2 n*(n-1) n n-1 n 1 2 cnt ans.reverse() ans.reverse ans reverse for ai in ans:
    print(ai) ai ans print(ai) print ai print(n*(n-1)//2) print n*(n-1)//2 n*(n-1) n n-1 n 1 2 n,m = map(int, input().split( )) map(int, input().split( )) n c = [1 for i in range(n+1)] [1 for i in range(n+1)] c p = [i for i in range(n+1)] [i for i in range(n+1)] p a,b = map(int, input().split( )) map(int, input().split( )) a cy=c[root(y)] c[root(y)] cy ans=[] [] ans def union(x,y):
    px = root(x); py = root(y)
    if px == py:
        return
    if r[px]>r[py]:
        p[py]=px
    else:
        p[px]=py
        if r[py]==r[px]:
            r[py]+=1 def union(x,y):
    px = root(x); py = root(y)
    if px == py:
        return
    if r[px]>r[py]:
        p[py]=px
    else:
        p[px]=py
        if r[py]==r[px]:
            r[py]+=1 union x,y = e[i] e[i] x y = e[i] e[i] y cx = c[root(x)] c[root(x)] cx cnt += (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 - cy*(cy-1)//2 (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 - cy*(cy-1)//2 cnt b = map(int, input().split( )) map(int, input().split( )) b def root(x):
    if p[x]==x:
        return x
    p[x] = y = root(p[x])
    return y def root(x):
    if p[x]==x:
        return x
    p[x] = y = root(p[x])
    return y root def same(x,y):
    px = root(x)
    py = root(y)
    if px==py:
        return True
    else:
        return False def same(x,y):
    px = root(x)
    py = root(y)
    if px==py:
        return True
    else:
        return False same r = [0 for i in range(n+1)] [0 for i in range(n+1)] r e = [] [] e cnt = 0 0 cnt m = map(int, input().split( )) map(int, input().split( )) m
#時系列の逆順で見る
def root(x):
    if p[x]==x:
        return x
    p[x] = y = root(p[x])
    return y
def union(x,y):
    px = root(x); py = root(y)
    if px == py:
        return
    if r[px]>r[py]:
        p[py]=px
    else:
        p[px]=py
        if r[py]==r[px]:
            r[py]+=1
def same(x,y):
    px = root(x)
    py = root(y)
    if px==py:
        return True
    else:
        return False
n,m = map(int, input().split( ))

e = []

for i in range(m):
    a,b = map(int, input().split( ))
    e.append((a,b))

e.reverse()
p = [i for i in range(n+1)]
r = [0 for i in range(n+1)]
c = [1 for i in range(n+1)]

cnt = 0
ans=[]
for i in range(m-1):
    x,y = e[i]
    if same(x,y):
        ans.append(n*(n-1)//2-cnt)
    else:
        cx = c[root(x)];cy=c[root(y)]
        union(x,y)
        cnt += (cx+cy)*(cx+cy-1)//2 - cx*(cx-1)//2 - cy*(cy-1)//2
        c[root(x)] = 0; c[root(y)]=0
        c[root(x)] = cx+cy
        ans.append(n*(n-1)//2-cnt)
ans.reverse()
for ai in ans:
    print(ai)
print(n*(n-1)//2)
    
    
