import sys
readline = sys.stdin.readline

class UnionFind:
  N=0
  parent=None
  size=None
  def __init__(self,N):
    self.N=N
    self.parent=[i for i in range(self.N)]
    self.size=[1]*self.N
    
  def root(self,x):
    while x!=self.parent[x]:
      self.parent[x]=self.parent[self.parent[x]]
      x=self.parent[x]
    return x
  
  def same(self,x,y):
    return self.root(x)==self.root(y)
  
  def unite(self,x,y):
    x=self.root(x)
    y=self.root(y)
    if x==y:
      return
    if self.size[x]>self.size[y]:
      # 大きい方にくっつける
      self.parent[y]=x
      self.size[x]+=self.size[y]
    else:
      self.parent[x]=y
      self.size[y]+=self.size[x]
      
  def get_group_size(self,x):
    return self.size[self.root(x)]
  
  def get_roots(self):
    r=set()
    for i in range(self.N):
      r.add(self.root(i))
    return r
  
  def show_parent(self):
    print(self.parent)
    
  def show_size(self):
    print(self.size)
    
N,M = map(int,readline().split())
bridges = [tuple(map(int,readline().split())) for i in range(M)]

# 順に崩落していく = 最後に崩落するものから順に建設されていくと考える
# 最初の不便さは(N * (N - 1)) // 2
# 新たにa,bの間に橋が繋がると、[aが属していた島々 * bが属していた島々]だけ不便さが減る
UF = UnionFind(N)
ans = [0] * M
num = (N * (N - 1)) // 2

for i in range(len(bridges) - 1, -1, -1):
  ans[i] = num
  a,b = bridges[i]
  a,b = a - 1,b - 1
  if not UF.same(a,b):
    num -= UF.get_group_size(a) * UF.get_group_size(b)
  UF.unite(a,b)

print(*ans, sep = "\n") import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline class UnionFind:
  N=0
  parent=None
  size=None
  def __init__(self,N):
    self.N=N
    self.parent=[i for i in range(self.N)]
    self.size=[1]*self.N
    
  def root(self,x):
    while x!=self.parent[x]:
      self.parent[x]=self.parent[self.parent[x]]
      x=self.parent[x]
    return x
  
  def same(self,x,y):
    return self.root(x)==self.root(y)
  
  def unite(self,x,y):
    x=self.root(x)
    y=self.root(y)
    if x==y:
      return
    if self.size[x]>self.size[y]:
      # 大きい方にくっつける
      self.parent[y]=x
      self.size[x]+=self.size[y]
    else:
      self.parent[x]=y
      self.size[y]+=self.size[x]
      
  def get_group_size(self,x):
    return self.size[self.root(x)]
  
  def get_roots(self):
    r=set()
    for i in range(self.N):
      r.add(self.root(i))
    return r
  
  def show_parent(self):
    print(self.parent)
    
  def show_size(self):
    print(self.size)
     UnionFind N=0 N 0 parent=None parent None size=None size None def __init__(self,N):
    self.N=N
    self.parent=[i for i in range(self.N)]
    self.size=[1]*self.N
    
   __init__ self.N=N self.N self N N i for i in range(self.N) for i in range(self.N) i range(self.N) range self.N self N for i in range(self.N) i self.parent=[i for i in range(self.N)] self.parent self parent [i for i in range(self.N)] self.size=[1]*self.N self.size self size [1]*self.N [1] 1 self.N self N self self N N def root(self,x):
    while x!=self.parent[x]:
      self.parent[x]=self.parent[self.parent[x]]
      x=self.parent[x]
    return x
  
   root while x!=self.parent[x]:
      self.parent[x]=self.parent[self.parent[x]]
      x=self.parent[x]
     x!=self.parent[x] x self.parent[x] self.parent self parent x self.parent[x]=self.parent[self.parent[x]] self.parent[x] self.parent self parent x self.parent[self.parent[x]] self.parent self parent self.parent[x] self.parent self parent x x=self.parent[x] x self.parent[x] self.parent self parent x return x x self self x x def same(self,x,y):
    return self.root(x)==self.root(y)
  
   same 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 unite(self,x,y):
    x=self.root(x)
    y=self.root(y)
    if x==y:
      return
    if self.size[x]>self.size[y]:
      # 大きい方にくっつける
      self.parent[y]=x
      self.size[x]+=self.size[y]
    else:
      self.parent[x]=y
      self.size[y]+=self.size[x]
      
   unite x=self.root(x) x self.root(x) self.root self root x y=self.root(y) y self.root(y) self.root self root y if x==y:
      return
     x==y x y return if self.size[x]>self.size[y]:
      # 大きい方にくっつける
      self.parent[y]=x
      self.size[x]+=self.size[y]
    else:
      self.parent[x]=y
      self.size[y]+=self.size[x]
      
   self.size[x]>self.size[y] self.size[x] self.size self size x self.size[y] self.size self size y self.parent[y]=x self.parent[y] self.parent self parent y x self.size[x]+=self.size[y] self.size[x] self.size self size x self.size[y] self.size self size y self.parent[x]=y self.parent[x] self.parent self parent x y self.size[y]+=self.size[x] self.size[y] self.size self size y self.size[x] self.size self size x self self x x y y def get_group_size(self,x):
    return self.size[self.root(x)]
  
   get_group_size return self.size[self.root(x)] self.size[self.root(x)] self.size self size self.root(x) self.root self root x self self x x def get_roots(self):
    r=set()
    for i in range(self.N):
      r.add(self.root(i))
    return r
  
   get_roots r=set() r set() set for i in range(self.N):
      r.add(self.root(i))
     i range(self.N) range self.N self N r.add(self.root(i)) r.add r add self.root(i) self.root self root i return r r self self def show_parent(self):
    print(self.parent)
    
   show_parent print(self.parent) print self.parent self parent self self def show_size(self):
    print(self.size)
     show_size print(self.size) print self.size self size self self N,M = map(int,readline().split()) N map(int,readline().split()) map int readline().split() ().split () readline split M tuple(map(int,readline().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) tuple(map(int,readline().split())) tuple map(int,readline().split()) map int readline().split() ().split () readline split bridges = [tuple(map(int,readline().split())) for i in range(M)] bridges [tuple(map(int,readline().split())) for i in range(M)] UF = UnionFind(N) UF UnionFind(N) UnionFind N ans = [0] * M ans [0] * M [0] 0 M num = (N * (N - 1)) // 2 num (N * (N - 1)) // 2 N * (N - 1) N N - 1 N 1 2 for i in range(len(bridges) - 1, -1, -1):
  ans[i] = num
  a,b = bridges[i]
  a,b = a - 1,b - 1
  if not UF.same(a,b):
    num -= UF.get_group_size(a) * UF.get_group_size(b)
  UF.unite(a,b) i range(len(bridges) - 1, -1, -1) range len(bridges) - 1 len(bridges) len bridges 1 -1 -1 ans[i] = num ans[i] ans i num a,b = bridges[i] a bridges[i] bridges i b a,b = a - 1,b - 1 a a - 1 a 1 b b - 1 b 1 if not UF.same(a,b):
    num -= UF.get_group_size(a) * UF.get_group_size(b)
   not UF.same(a,b) UF.same(a,b) UF.same UF same a b num -= UF.get_group_size(a) * UF.get_group_size(b) num UF.get_group_size(a) * UF.get_group_size(b) UF.get_group_size(a) UF.get_group_size UF get_group_size a UF.get_group_size(b) UF.get_group_size UF get_group_size b UF.unite(a,b) UF.unite UF unite a b print(*ans, sep = "\n") print *ans ans sep = "\n" sep "\n" num = (N * (N - 1)) // 2 (N * (N - 1)) // 2 num class UnionFind:
  N=0
  parent=None
  size=None
  def __init__(self,N):
    self.N=N
    self.parent=[i for i in range(self.N)]
    self.size=[1]*self.N
    
  def root(self,x):
    while x!=self.parent[x]:
      self.parent[x]=self.parent[self.parent[x]]
      x=self.parent[x]
    return x
  
  def same(self,x,y):
    return self.root(x)==self.root(y)
  
  def unite(self,x,y):
    x=self.root(x)
    y=self.root(y)
    if x==y:
      return
    if self.size[x]>self.size[y]:
      # 大きい方にくっつける
      self.parent[y]=x
      self.size[x]+=self.size[y]
    else:
      self.parent[x]=y
      self.size[y]+=self.size[x]
      
  def get_group_size(self,x):
    return self.size[self.root(x)]
  
  def get_roots(self):
    r=set()
    for i in range(self.N):
      r.add(self.root(i))
    return r
  
  def show_parent(self):
    print(self.parent)
    
  def show_size(self):
    print(self.size)
     class UnionFind:
  N=0
  parent=None
  size=None
  def __init__(self,N):
    self.N=N
    self.parent=[i for i in range(self.N)]
    self.size=[1]*self.N
    
  def root(self,x):
    while x!=self.parent[x]:
      self.parent[x]=self.parent[self.parent[x]]
      x=self.parent[x]
    return x
  
  def same(self,x,y):
    return self.root(x)==self.root(y)
  
  def unite(self,x,y):
    x=self.root(x)
    y=self.root(y)
    if x==y:
      return
    if self.size[x]>self.size[y]:
      # 大きい方にくっつける
      self.parent[y]=x
      self.size[x]+=self.size[y]
    else:
      self.parent[x]=y
      self.size[y]+=self.size[x]
      
  def get_group_size(self,x):
    return self.size[self.root(x)]
  
  def get_roots(self):
    r=set()
    for i in range(self.N):
      r.add(self.root(i))
    return r
  
  def show_parent(self):
    print(self.parent)
    
  def show_size(self):
    print(self.size)
     UnionFind b = bridges[i] bridges[i] b num -= UF.get_group_size(a) * UF.get_group_size(b) UF.get_group_size(a) * UF.get_group_size(b) num a,b = a - 1,b - 1 a - 1 a bridges = [tuple(map(int,readline().split())) for i in range(M)] [tuple(map(int,readline().split())) for i in range(M)] bridges N,M = map(int,readline().split()) map(int,readline().split()) N M = map(int,readline().split()) map(int,readline().split()) M b = a - 1,b - 1 b - 1 b a,b = bridges[i] bridges[i] a readline = sys.stdin.readline sys.stdin.readline readline ans = [0] * M [0] * M ans UF = UnionFind(N) UnionFind(N) UF
import sys
readline = sys.stdin.readline

class UnionFind:
  N=0
  parent=None
  size=None
  def __init__(self,N):
    self.N=N
    self.parent=[i for i in range(self.N)]
    self.size=[1]*self.N
    
  def root(self,x):
    while x!=self.parent[x]:
      self.parent[x]=self.parent[self.parent[x]]
      x=self.parent[x]
    return x
  
  def same(self,x,y):
    return self.root(x)==self.root(y)
  
  def unite(self,x,y):
    x=self.root(x)
    y=self.root(y)
    if x==y:
      return
    if self.size[x]>self.size[y]:
      # 大きい方にくっつける
      self.parent[y]=x
      self.size[x]+=self.size[y]
    else:
      self.parent[x]=y
      self.size[y]+=self.size[x]
      
  def get_group_size(self,x):
    return self.size[self.root(x)]
  
  def get_roots(self):
    r=set()
    for i in range(self.N):
      r.add(self.root(i))
    return r
  
  def show_parent(self):
    print(self.parent)
    
  def show_size(self):
    print(self.size)
    
N,M = map(int,readline().split())
bridges = [tuple(map(int,readline().split())) for i in range(M)]

# 順に崩落していく = 最後に崩落するものから順に建設されていくと考える
# 最初の不便さは(N * (N - 1)) // 2
# 新たにa,bの間に橋が繋がると、[aが属していた島々 * bが属していた島々]だけ不便さが減る
UF = UnionFind(N)
ans = [0] * M
num = (N * (N - 1)) // 2

for i in range(len(bridges) - 1, -1, -1):
  ans[i] = num
  a,b = bridges[i]
  a,b = a - 1,b - 1
  if not UF.same(a,b):
    num -= UF.get_group_size(a) * UF.get_group_size(b)
  UF.unite(a,b)

print(*ans, sep = "\n")