import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
sys.setrecursionlimit(200000)
b=[tuple(map(lambda x: int(x)-1, input().split())) for i in range(M)]
class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def size(self,n):
        return -self.l[self.ro(n)]
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
    def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
    def len(self):          #len(roots)
        return len(self.rl())
    def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
    def __str__(self):
        return f"{self.ul()}"
l=[0]*M
s=uf(N)
h=N*(N-1)//2
for i in range(M-1,-1,-1):
    l[i]=h
    if s.ro(b[i][0])!=s.ro(b[i][1]):
        h-=s.size(b[i][0])*s.size(b[i][1])
        s.me(b[i][0],b[i][1])
print(*l,sep="\n") import sys sys def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M sys.setrecursionlimit(200000) sys.setrecursionlimit sys setrecursionlimit 200000 tuple(map(lambda x: int(x)-1, input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) tuple(map(lambda x: int(x)-1, input().split())) tuple map(lambda x: int(x)-1, input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split b=[tuple(map(lambda x: int(x)-1, input().split())) for i in range(M)] b [tuple(map(lambda x: int(x)-1, input().split())) for i in range(M)] class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def size(self,n):
        return -self.l[self.ro(n)]
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
    def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
    def len(self):          #len(roots)
        return len(self.rl())
    def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
    def __str__(self):
        return f"{self.ul()}" uf def __init__(self,n):
        self.n=n
        self.l=[-1]*n
     __init__ self.n=n self.n self n n self.l=[-1]*n self.l self l [-1]*n [-1] -1 n self self n n def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
     ro if self.l[n]<0:
            return n
         self.l[n]<0 self.l[n] self.l self l n 0 return n n r=self.ro(self.l[n]) r self.ro(self.l[n]) self.ro self ro self.l[n] self.l self l n self.l[n]=r self.l[n] self.l self l n r return r r self self n n def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
     me ra=self.ro(a) ra self.ro(a) self.ro self ro a rb=self.ro(b) rb self.ro(b) self.ro self ro b if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
         self.l[ra]>self.l[rb] self.l[ra] self.l self l ra self.l[rb] self.l self l rb ra,rb=rb,ra ra rb rb ra if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
     ra!=rb ra rb self.l[ra]+=self.l[rb] self.l[ra] self.l self l ra self.l[rb] self.l self l rb self.l[rb]=ra self.l[rb] self.l self l rb ra self self a a b b def size(self,n):
        return -self.l[self.ro(n)]
     size return -self.l[self.ro(n)] -self.l[self.ro(n)] self.l[self.ro(n)] self.l self l self.ro(n) self.ro self ro n self self n n def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
     sa return self.ro(a)==self.ro(b) self.ro(a)==self.ro(b) self.ro(a) self.ro self ro a self.ro(b) self.ro self ro b self self a a b b def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
     rl i for i,v in enumerate(self.l) if v<0 for i,v in enumerate(self.l) if v<0 i v enumerate(self.l) enumerate self.l self l v<0 v 0 if v<0 i return [i for i,v in enumerate(self.l) if v<0] [i for i,v in enumerate(self.l) if v<0] self self def len(self):          #len(roots)
        return len(self.rl())
     len return len(self.rl()) len(self.rl()) len self.rl() self.rl self rl self self def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
     ul n:i for i,n in enumerate(self.rl()) for i,n in enumerate(self.rl()) i n enumerate(self.rl()) enumerate self.rl() self.rl self rl for i,n in enumerate(self.rl()) n i d={n:i for i,n in enumerate(self.rl())} d {n:i for i,n in enumerate(self.rl())} []for i in range(self.len()) for i in range(self.len()) i range(self.len()) range self.len() self.len self len for i in range(self.len()) [] m=[[]for i in range(self.len())] m [[]for i in range(self.len())] for i in range(self.n):
            m[d[self.ro(i)]].append(i)
         i range(self.n) range self.n self n m[d[self.ro(i)]].append(i) [d[self.ro(i)]].append [d[self.ro(i)]] m d[self.ro(i)] d self.ro(i) self.ro self ro i append i return m m self self def __str__(self):
        return f"{self.ul()}" __str__ return f"{self.ul()}" f"{self.ul()}" self self l=[0]*M l [0]*M [0] 0 M s=uf(N) s uf(N) uf N h=N*(N-1)//2 h N*(N-1)//2 N*(N-1) N N-1 N 1 2 for i in range(M-1,-1,-1):
    l[i]=h
    if s.ro(b[i][0])!=s.ro(b[i][1]):
        h-=s.size(b[i][0])*s.size(b[i][1])
        s.me(b[i][0],b[i][1]) i range(M-1,-1,-1) range M-1 M 1 -1 -1 l[i]=h l[i] l i h if s.ro(b[i][0])!=s.ro(b[i][1]):
        h-=s.size(b[i][0])*s.size(b[i][1])
        s.me(b[i][0],b[i][1]) s.ro(b[i][0])!=s.ro(b[i][1]) s.ro(b[i][0]) s.ro s ro b[i][0] [i] b i 0 s.ro(b[i][1]) s.ro s ro b[i][1] [i] b i 1 h-=s.size(b[i][0])*s.size(b[i][1]) h s.size(b[i][0])*s.size(b[i][1]) s.size(b[i][0]) s.size s size b[i][0] [i] b i 0 s.size(b[i][1]) s.size s size b[i][1] [i] b i 1 s.me(b[i][0],b[i][1]) s.me s me b[i][0] [i] b i 0 b[i][1] [i] b i 1 print(*l,sep="\n") print *l l sep="\n" sep "\n" class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def size(self,n):
        return -self.l[self.ro(n)]
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
    def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
    def len(self):          #len(roots)
        return len(self.rl())
    def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
    def __str__(self):
        return f"{self.ul()}" class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def size(self,n):
        return -self.l[self.ro(n)]
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
    def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
    def len(self):          #len(roots)
        return len(self.rl())
    def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
    def __str__(self):
        return f"{self.ul()}" uf def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input M=map(int,input().split()) map(int,input().split()) M N,M=map(int,input().split()) map(int,input().split()) N b=[tuple(map(lambda x: int(x)-1, input().split())) for i in range(M)] [tuple(map(lambda x: int(x)-1, input().split())) for i in range(M)] b h=N*(N-1)//2 N*(N-1)//2 h l=[0]*M [0]*M l h-=s.size(b[i][0])*s.size(b[i][1]) s.size(b[i][0])*s.size(b[i][1]) h s=uf(N) uf(N) s
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
sys.setrecursionlimit(200000)
b=[tuple(map(lambda x: int(x)-1, input().split())) for i in range(M)]
class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def size(self,n):
        return -self.l[self.ro(n)]
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
    def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
    def len(self):          #len(roots)
        return len(self.rl())
    def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
    def __str__(self):
        return f"{self.ul()}"
l=[0]*M
s=uf(N)
h=N*(N-1)//2
for i in range(M-1,-1,-1):
    l[i]=h
    if s.ro(b[i][0])!=s.ro(b[i][1]):
        h-=s.size(b[i][0])*s.size(b[i][1])
        s.me(b[i][0],b[i][1])
print(*l,sep="\n")