import sys
sys.setrecursionlimit(10**9)
from collections import Counter
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict
input = sys.stdin.readline
    
icase=0
if icase==0:
    n,m=map(int,input().split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ai,bi=map(int,input().split())
        a[i]=ai-1
        b[i]=bi-1
elif icase==1:
    n,m=4,5
    a=[0, 2, 0, 1, 0]
    b=[1, 3, 2, 2, 3]
elif icase==2:
    n,m=6,5
    a=[1, 0, 4, 2, 3]
    b=[2, 1, 5, 3, 4]
elif icase==3:
    n,m=26,25
    a=[13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8]
    b=[14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11]
elif icase==4:
    f=open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat")
    ll=f.readline()
    n,m=map(int,ll.split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ll=f.readline()
        ai,bi=map(int,ll.split())
        a[i]=ai-1
        b[i]=bi-1
    f.close()

pair=[i for i in range(n)]

def root(x):
    if x==pair[x]:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp

def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:
        return
    elif x>y:
        pair[x]=y
    else:
        pair[y]=x

def q087():
    cc=[]
    c1=[1]*n
    c2=defaultdict(int)
    c2[1]=n
    c=n    
#    pair=[i for i in range(n)]
    for i in range(m-1):
#------------------------
        rta=root(a[m-i-1])
        rtb=root(b[m-i-1])
        if c1[rta]>=n or c1[rtb]>=n:
            cc.append(0)
            continue
        if rta<rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rta]+=c1[rtb]
            c1[rtb]=0
            d1=c1[rta]
#        pair[rtb]=rta
            unite(a[m-i-1],b[m-i-1])
        elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
        else:
            cc.append(c)
            continue

        c2[d1]+=1    
        if c2[d2]>0:
            c2[d2]-=1
#    if c2[d2]==0:
#        del c2[d2]
        if c2[d3]>0:
            c2[d3]-=1
#    if c2[d3]==0:
#        del c2[d3]
#    print(c1)        
#    print(c2)     
        q=[]
        for c2k,c2v in c2.items():
            if c2v==0:
                q.append(c2k)
        while q:
            del c2[q.pop()]            
#    print(c2)     
        c3=[]
        for c2k,c2v in c2.items():
            c3.append((c2k,c2k*c2v))

        c=0
#    for i in range(len(c3)):
        for i,c3i in enumerate(c3):
            c+=c3i[1]*(c3i[1]-c3i[0])//2
#        for j in range(i+1,len(c3)):
            for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
        cc.append(c)

    for i in range(m-2,-1,-1):
        print(cc[i])
    print(n*(n-1)//2)
#-------------------------------
q087()
#-------------------------------
 import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 from collections import Counter from itertools import permutations, combinations,combinations_with_replacement,product from collections import defaultdict input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline icase=0 icase 0 if icase==0:
    n,m=map(int,input().split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ai,bi=map(int,input().split())
        a[i]=ai-1
        b[i]=bi-1
elif icase==1:
    n,m=4,5
    a=[0, 2, 0, 1, 0]
    b=[1, 3, 2, 2, 3]
elif icase==2:
    n,m=6,5
    a=[1, 0, 4, 2, 3]
    b=[2, 1, 5, 3, 4]
elif icase==3:
    n,m=26,25
    a=[13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8]
    b=[14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11]
elif icase==4:
    f=open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat")
    ll=f.readline()
    n,m=map(int,ll.split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ll=f.readline()
        ai,bi=map(int,ll.split())
        a[i]=ai-1
        b[i]=bi-1
    f.close() icase==0 icase 0 n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a=[0]*m a [0]*m [0] 0 m b=[0]*m b [0]*m [0] 0 m for i in range(m):
        ai,bi=map(int,input().split())
        a[i]=ai-1
        b[i]=bi-1 i range(m) range m ai,bi=map(int,input().split()) ai map(int,input().split()) map int input().split() ().split () input split bi a[i]=ai-1 a[i] a i ai-1 ai 1 b[i]=bi-1 b[i] b i bi-1 bi 1 elif icase==1:
    n,m=4,5
    a=[0, 2, 0, 1, 0]
    b=[1, 3, 2, 2, 3] icase==1 icase 1 n,m=4,5 n 4 m 5 a=[0, 2, 0, 1, 0] a [0, 2, 0, 1, 0] 0 2 0 1 0 b=[1, 3, 2, 2, 3] b [1, 3, 2, 2, 3] 1 3 2 2 3 elif icase==2:
    n,m=6,5
    a=[1, 0, 4, 2, 3]
    b=[2, 1, 5, 3, 4] icase==2 icase 2 n,m=6,5 n 6 m 5 a=[1, 0, 4, 2, 3] a [1, 0, 4, 2, 3] 1 0 4 2 3 b=[2, 1, 5, 3, 4] b [2, 1, 5, 3, 4] 2 1 5 3 4 elif icase==3:
    n,m=26,25
    a=[13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8]
    b=[14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11] icase==3 icase 3 n,m=26,25 n 26 m 25 a=[13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8] a [13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8] 13 13 7 1 20 0 2 3 5 13 0 0 16 3 1 15 13 13 16 9 13 8 12 6 8 b=[14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11] b [14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11] 14 18 25 20 24 19 13 13 21 22 14 4 23 25 10 17 17 20 20 14 21 9 22 9 11 elif icase==4:
    f=open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat")
    ll=f.readline()
    n,m=map(int,ll.split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ll=f.readline()
        ai,bi=map(int,ll.split())
        a[i]=ai-1
        b[i]=bi-1
    f.close() icase==4 icase 4 f=open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat") f open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat") open r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat" ll=f.readline() ll f.readline() f.readline f readline n,m=map(int,ll.split()) n map(int,ll.split()) map int ll.split() ll.split ll split m a=[0]*m a [0]*m [0] 0 m b=[0]*m b [0]*m [0] 0 m for i in range(m):
        ll=f.readline()
        ai,bi=map(int,ll.split())
        a[i]=ai-1
        b[i]=bi-1
     i range(m) range m ll=f.readline() ll f.readline() f.readline f readline ai,bi=map(int,ll.split()) ai map(int,ll.split()) map int ll.split() ll.split ll split bi a[i]=ai-1 a[i] a i ai-1 ai 1 b[i]=bi-1 b[i] b i bi-1 bi 1 f.close() f.close f close i for i in range(n) for i in range(n) i range(n) range n for i in range(n) i pair=[i for i in range(n)] pair [i for i in range(n)] def root(x):
    if x==pair[x]:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp root if x==pair[x]:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp x==pair[x] x pair[x] pair x return x x tmp=root(pair[x]) tmp root(pair[x]) root pair[x] pair x pair[x]=tmp pair[x] pair x tmp return tmp tmp x x def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:
        return
    elif x>y:
        pair[x]=y
    else:
        pair[y]=x unite x=root(x) x root(x) root x y=root(y) y root(y) root y if x==y:
        return
    elif x>y:
        pair[x]=y
    else:
        pair[y]=x x==y x y return elif x>y:
        pair[x]=y
     x>y x y pair[x]=y pair[x] pair x y pair[y]=x pair[y] pair y x x x y y def q087():
    cc=[]
    c1=[1]*n
    c2=defaultdict(int)
    c2[1]=n
    c=n    
#    pair=[i for i in range(n)]
    for i in range(m-1):
#------------------------
        rta=root(a[m-i-1])
        rtb=root(b[m-i-1])
        if c1[rta]>=n or c1[rtb]>=n:
            cc.append(0)
            continue
        if rta<rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rta]+=c1[rtb]
            c1[rtb]=0
            d1=c1[rta]
#        pair[rtb]=rta
            unite(a[m-i-1],b[m-i-1])
        elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
        else:
            cc.append(c)
            continue

        c2[d1]+=1    
        if c2[d2]>0:
            c2[d2]-=1
#    if c2[d2]==0:
#        del c2[d2]
        if c2[d3]>0:
            c2[d3]-=1
#    if c2[d3]==0:
#        del c2[d3]
#    print(c1)        
#    print(c2)     
        q=[]
        for c2k,c2v in c2.items():
            if c2v==0:
                q.append(c2k)
        while q:
            del c2[q.pop()]            
#    print(c2)     
        c3=[]
        for c2k,c2v in c2.items():
            c3.append((c2k,c2k*c2v))

        c=0
#    for i in range(len(c3)):
        for i,c3i in enumerate(c3):
            c+=c3i[1]*(c3i[1]-c3i[0])//2
#        for j in range(i+1,len(c3)):
            for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
        cc.append(c)

    for i in range(m-2,-1,-1):
        print(cc[i])
    print(n*(n-1)//2)
#------------------------------- q087 cc=[] cc [] c1=[1]*n c1 [1]*n [1] 1 n c2=defaultdict(int) c2 defaultdict(int) defaultdict int c2[1]=n c2[1] c2 1 n c=n c n for i in range(m-1):
#------------------------
        rta=root(a[m-i-1])
        rtb=root(b[m-i-1])
        if c1[rta]>=n or c1[rtb]>=n:
            cc.append(0)
            continue
        if rta<rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rta]+=c1[rtb]
            c1[rtb]=0
            d1=c1[rta]
#        pair[rtb]=rta
            unite(a[m-i-1],b[m-i-1])
        elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
        else:
            cc.append(c)
            continue

        c2[d1]+=1    
        if c2[d2]>0:
            c2[d2]-=1
#    if c2[d2]==0:
#        del c2[d2]
        if c2[d3]>0:
            c2[d3]-=1
#    if c2[d3]==0:
#        del c2[d3]
#    print(c1)        
#    print(c2)     
        q=[]
        for c2k,c2v in c2.items():
            if c2v==0:
                q.append(c2k)
        while q:
            del c2[q.pop()]            
#    print(c2)     
        c3=[]
        for c2k,c2v in c2.items():
            c3.append((c2k,c2k*c2v))

        c=0
#    for i in range(len(c3)):
        for i,c3i in enumerate(c3):
            c+=c3i[1]*(c3i[1]-c3i[0])//2
#        for j in range(i+1,len(c3)):
            for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
        cc.append(c)

     i range(m-1) range m-1 m 1 rta=root(a[m-i-1]) rta root(a[m-i-1]) root a[m-i-1] a m-i-1 m-i m i 1 rtb=root(b[m-i-1]) rtb root(b[m-i-1]) root b[m-i-1] b m-i-1 m-i m i 1 if c1[rta]>=n or c1[rtb]>=n:
            cc.append(0)
            continue
         c1[rta]>=n or c1[rtb]>=n c1[rta]>=n c1[rta] c1 rta n c1[rtb]>=n c1[rtb] c1 rtb n cc.append(0) cc.append cc append 0 continue if rta<rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rta]+=c1[rtb]
            c1[rtb]=0
            d1=c1[rta]
#        pair[rtb]=rta
            unite(a[m-i-1],b[m-i-1])
        elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
        else:
            cc.append(c)
            continue

         rta<rtb rta rtb d2=c1[rta] d2 c1[rta] c1 rta d3=c1[rtb] d3 c1[rtb] c1 rtb c1[rta]+=c1[rtb] c1[rta] c1 rta c1[rtb] c1 rtb c1[rtb]=0 c1[rtb] c1 rtb 0 d1=c1[rta] d1 c1[rta] c1 rta unite(a[m-i-1],b[m-i-1]) unite a[m-i-1] a m-i-1 m-i m i 1 b[m-i-1] b m-i-1 m-i m i 1 elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
         rta>rtb rta rtb d2=c1[rta] d2 c1[rta] c1 rta d3=c1[rtb] d3 c1[rtb] c1 rtb c1[rtb]+=c1[rta] c1[rtb] c1 rtb c1[rta] c1 rta c1[rta]=0 c1[rta] c1 rta 0 d1=c1[rtb] d1 c1[rtb] c1 rtb unite(a[m-i-1],b[m-i-1]) unite a[m-i-1] a m-i-1 m-i m i 1 b[m-i-1] b m-i-1 m-i m i 1 cc.append(c) cc.append cc append c continue c2[d1]+=1 c2[d1] c2 d1 1 if c2[d2]>0:
            c2[d2]-=1
#    if c2[d2]==0:
#        del c2[d2]
         c2[d2]>0 c2[d2] c2 d2 0 c2[d2]-=1 c2[d2] c2 d2 1 if c2[d3]>0:
            c2[d3]-=1
#    if c2[d3]==0:
#        del c2[d3]
#    print(c1)        
#    print(c2)     
         c2[d3]>0 c2[d3] c2 d3 0 c2[d3]-=1 c2[d3] c2 d3 1 q=[] q [] for c2k,c2v in c2.items():
            if c2v==0:
                q.append(c2k)
         c2k c2v c2.items() c2.items c2 items if c2v==0:
                q.append(c2k)
         c2v==0 c2v 0 q.append(c2k) q.append q append c2k while q:
            del c2[q.pop()]            
#    print(c2)     
         q del c2[q.pop()] c2[q.pop()] c2 q.pop() q.pop q pop c3=[] c3 [] for c2k,c2v in c2.items():
            c3.append((c2k,c2k*c2v))

         c2k c2v c2.items() c2.items c2 items c3.append((c2k,c2k*c2v)) c3.append c3 append (c2k,c2k*c2v) c2k c2k*c2v c2k c2v c=0 c 0 for i,c3i in enumerate(c3):
            c+=c3i[1]*(c3i[1]-c3i[0])//2
#        for j in range(i+1,len(c3)):
            for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
         i c3i enumerate(c3) enumerate c3 c+=c3i[1]*(c3i[1]-c3i[0])//2 c c3i[1]*(c3i[1]-c3i[0])//2 c3i[1]*(c3i[1]-c3i[0]) c3i[1] c3i 1 c3i[1]-c3i[0] c3i[1] c3i 1 c3i[0] c3i 0 2 for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
         j c3j enumerate(c3[0:i]) enumerate c3[0:i] c3 0:i 0 i c+=c3i[1]*c3j[1] c c3i[1]*c3j[1] c3i[1] c3i 1 c3j[1] c3j 1 cc.append(c) cc.append cc append c for i in range(m-2,-1,-1):
        print(cc[i])
     i range(m-2,-1,-1) range m-2 m 2 -1 -1 print(cc[i]) print cc[i] cc i print(n*(n-1)//2) print n*(n-1)//2 n*(n-1) n n-1 n 1 2 q087() q087 def q087():
    cc=[]
    c1=[1]*n
    c2=defaultdict(int)
    c2[1]=n
    c=n    
#    pair=[i for i in range(n)]
    for i in range(m-1):
#------------------------
        rta=root(a[m-i-1])
        rtb=root(b[m-i-1])
        if c1[rta]>=n or c1[rtb]>=n:
            cc.append(0)
            continue
        if rta<rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rta]+=c1[rtb]
            c1[rtb]=0
            d1=c1[rta]
#        pair[rtb]=rta
            unite(a[m-i-1],b[m-i-1])
        elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
        else:
            cc.append(c)
            continue

        c2[d1]+=1    
        if c2[d2]>0:
            c2[d2]-=1
#    if c2[d2]==0:
#        del c2[d2]
        if c2[d3]>0:
            c2[d3]-=1
#    if c2[d3]==0:
#        del c2[d3]
#    print(c1)        
#    print(c2)     
        q=[]
        for c2k,c2v in c2.items():
            if c2v==0:
                q.append(c2k)
        while q:
            del c2[q.pop()]            
#    print(c2)     
        c3=[]
        for c2k,c2v in c2.items():
            c3.append((c2k,c2k*c2v))

        c=0
#    for i in range(len(c3)):
        for i,c3i in enumerate(c3):
            c+=c3i[1]*(c3i[1]-c3i[0])//2
#        for j in range(i+1,len(c3)):
            for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
        cc.append(c)

    for i in range(m-2,-1,-1):
        print(cc[i])
    print(n*(n-1)//2)
#------------------------------- def q087():
    cc=[]
    c1=[1]*n
    c2=defaultdict(int)
    c2[1]=n
    c=n    
#    pair=[i for i in range(n)]
    for i in range(m-1):
#------------------------
        rta=root(a[m-i-1])
        rtb=root(b[m-i-1])
        if c1[rta]>=n or c1[rtb]>=n:
            cc.append(0)
            continue
        if rta<rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rta]+=c1[rtb]
            c1[rtb]=0
            d1=c1[rta]
#        pair[rtb]=rta
            unite(a[m-i-1],b[m-i-1])
        elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
        else:
            cc.append(c)
            continue

        c2[d1]+=1    
        if c2[d2]>0:
            c2[d2]-=1
#    if c2[d2]==0:
#        del c2[d2]
        if c2[d3]>0:
            c2[d3]-=1
#    if c2[d3]==0:
#        del c2[d3]
#    print(c1)        
#    print(c2)     
        q=[]
        for c2k,c2v in c2.items():
            if c2v==0:
                q.append(c2k)
        while q:
            del c2[q.pop()]            
#    print(c2)     
        c3=[]
        for c2k,c2v in c2.items():
            c3.append((c2k,c2k*c2v))

        c=0
#    for i in range(len(c3)):
        for i,c3i in enumerate(c3):
            c+=c3i[1]*(c3i[1]-c3i[0])//2
#        for j in range(i+1,len(c3)):
            for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
        cc.append(c)

    for i in range(m-2,-1,-1):
        print(cc[i])
    print(n*(n-1)//2)
#------------------------------- q087 pair=[i for i in range(n)] [i for i in range(n)] pair f=open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat") open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat") f def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:
        return
    elif x>y:
        pair[x]=y
    else:
        pair[y]=x def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:
        return
    elif x>y:
        pair[x]=y
    else:
        pair[y]=x unite icase=0 0 icase b=[14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11] [14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11] b a=[0, 2, 0, 1, 0] [0, 2, 0, 1, 0] a n,m=map(int,input().split()) map(int,input().split()) n b=[0]*m [0]*m b m=map(int,ll.split()) map(int,ll.split()) m def root(x):
    if x==pair[x]:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp def root(x):
    if x==pair[x]:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp root b=[0]*m [0]*m b m=6,5 5 m m=4,5 5 m bi=map(int,ll.split()) map(int,ll.split()) bi n,m=map(int,ll.split()) map(int,ll.split()) n ll=f.readline() f.readline() ll ll=f.readline() f.readline() ll n,m=26,25 26 n a=[1, 0, 4, 2, 3] [1, 0, 4, 2, 3] a m=26,25 25 m b=[2, 1, 5, 3, 4] [2, 1, 5, 3, 4] b ai,bi=map(int,ll.split()) map(int,ll.split()) ai n,m=6,5 6 n input = sys.stdin.readline sys.stdin.readline input b=[1, 3, 2, 2, 3] [1, 3, 2, 2, 3] b a=[0]*m [0]*m a bi=map(int,input().split()) map(int,input().split()) bi a=[0]*m [0]*m a m=map(int,input().split()) map(int,input().split()) m ai,bi=map(int,input().split()) map(int,input().split()) ai n,m=4,5 4 n a=[13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8] [13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8] a
import sys
sys.setrecursionlimit(10**9)
from collections import Counter
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict
input = sys.stdin.readline
    
icase=0
if icase==0:
    n,m=map(int,input().split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ai,bi=map(int,input().split())
        a[i]=ai-1
        b[i]=bi-1
elif icase==1:
    n,m=4,5
    a=[0, 2, 0, 1, 0]
    b=[1, 3, 2, 2, 3]
elif icase==2:
    n,m=6,5
    a=[1, 0, 4, 2, 3]
    b=[2, 1, 5, 3, 4]
elif icase==3:
    n,m=26,25
    a=[13, 13, 7, 1, 20, 0, 2, 3, 5, 13, 0, 0, 16, 3, 1, 15, 13, 13, 16, 9, 13, 8, 12, 6, 8]
    b=[14, 18, 25, 20, 24, 19, 13, 13, 21, 22, 14, 4, 23, 25, 10, 17, 17, 20, 20, 14, 21, 9, 22, 9, 11]
elif icase==4:
    f=open(r"C:\Users\nishi\999atcoder\q100\q087\testcase_01_in.dat")
    ll=f.readline()
    n,m=map(int,ll.split())
    a=[0]*m
    b=[0]*m
    for i in range(m):
        ll=f.readline()
        ai,bi=map(int,ll.split())
        a[i]=ai-1
        b[i]=bi-1
    f.close()

pair=[i for i in range(n)]

def root(x):
    if x==pair[x]:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp

def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:
        return
    elif x>y:
        pair[x]=y
    else:
        pair[y]=x

def q087():
    cc=[]
    c1=[1]*n
    c2=defaultdict(int)
    c2[1]=n
    c=n    
#    pair=[i for i in range(n)]
    for i in range(m-1):
#------------------------
        rta=root(a[m-i-1])
        rtb=root(b[m-i-1])
        if c1[rta]>=n or c1[rtb]>=n:
            cc.append(0)
            continue
        if rta<rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rta]+=c1[rtb]
            c1[rtb]=0
            d1=c1[rta]
#        pair[rtb]=rta
            unite(a[m-i-1],b[m-i-1])
        elif rta>rtb:
            d2=c1[rta]
            d3=c1[rtb]
            c1[rtb]+=c1[rta]
            c1[rta]=0
            d1=c1[rtb]
#        pair[rta]=rtb
            unite(a[m-i-1],b[m-i-1])
        else:
            cc.append(c)
            continue

        c2[d1]+=1    
        if c2[d2]>0:
            c2[d2]-=1
#    if c2[d2]==0:
#        del c2[d2]
        if c2[d3]>0:
            c2[d3]-=1
#    if c2[d3]==0:
#        del c2[d3]
#    print(c1)        
#    print(c2)     
        q=[]
        for c2k,c2v in c2.items():
            if c2v==0:
                q.append(c2k)
        while q:
            del c2[q.pop()]            
#    print(c2)     
        c3=[]
        for c2k,c2v in c2.items():
            c3.append((c2k,c2k*c2v))

        c=0
#    for i in range(len(c3)):
        for i,c3i in enumerate(c3):
            c+=c3i[1]*(c3i[1]-c3i[0])//2
#        for j in range(i+1,len(c3)):
            for j,c3j in enumerate(c3[0:i]):
                c+=c3i[1]*c3j[1]
        cc.append(c)

    for i in range(m-2,-1,-1):
        print(cc[i])
    print(n*(n-1)//2)
#-------------------------------
q087()
#-------------------------------

