import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
    
n,m = map(int, input().split())
uf = UnionFindTree(n)
ans = [None] * m
val = n * (n-1) // 2
ab = [None] * m
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ab[i] = (a,b)
i = 0
for a,b in ab[::-1]:
    ans[m-1-i] = val
    i += 1
    ra = uf.root(a)
    rb = uf.root(b)
    if ra==rb:
        pass
    else:
        val -= uf.size[ra] * uf.size[rb]
    uf.connect(a,b)
write("\n".join(map(str, ans))) import sys sys input = lambda : sys.stdin.readline().rstrip() input lambda : sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip sys.setrecursionlimit(max(1000, 10**9)) sys.setrecursionlimit sys setrecursionlimit max(1000, 10**9) max 1000 10**9 10 9 write = lambda x: sys.stdout.write(x+"\n") write lambda x: sys.stdout.write(x+"\n") sys.stdout.write(x+"\n") sys.stdout.write sys.stdout sys stdout write x+"\n" x "\n" x class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
     UnionFindTree def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

     __init__ self.n = n self.n self n n self.parent = list(range(n)) self.parent self parent list(range(n)) list range(n) range n self.size = [1] * n self.size self size [1] * n [1] 1 n self self n n def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

     root inter = set() inter set() set while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
         self.parent[i]!=i self.parent[i] self.parent self parent i i inter.add(i) inter.add inter add i i = self.parent[i] i self.parent[i] self.parent self parent i r = i r i for i in inter:
            self.parent[i] = r
         i inter self.parent[i] = r self.parent[i] self.parent self parent i r return r r self self i i def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
     connect if i==j:
            return
         i==j i j return ri = self.root(i) ri self.root(i) self.root self root i rj = self.root(j) rj self.root(j) self.root self root j if ri==rj:
            return
         ri==rj ri rj return if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
     self.size[ri]<self.size[rj] self.size[ri] self.size self size ri self.size[rj] self.size self size rj self.parent[ri] = rj self.parent[ri] self.parent self parent ri rj self.size[rj] += self.size[ri] self.size[rj] self.size self size rj self.size[ri] self.size self size ri self.parent[rj] = ri self.parent[rj] self.parent self parent rj ri self.size[ri] += self.size[rj] self.size[ri] self.size self size ri self.size[rj] self.size self size rj self self i i j j n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m uf = UnionFindTree(n) uf UnionFindTree(n) UnionFindTree n ans = [None] * m ans [None] * m [None] None m val = n * (n-1) // 2 val n * (n-1) // 2 n * (n-1) n n-1 n 1 2 ab = [None] * m ab [None] * m [None] None m for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ab[i] = (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 a -= 1 a 1 b -= 1 b 1 ab[i] = (a,b) ab[i] ab i (a,b) a b i = 0 i 0 for a,b in ab[::-1]:
    ans[m-1-i] = val
    i += 1
    ra = uf.root(a)
    rb = uf.root(b)
    if ra==rb:
        pass
    else:
        val -= uf.size[ra] * uf.size[rb]
    uf.connect(a,b) a b ab[::-1] ab ::-1 -1 ans[m-1-i] = val ans[m-1-i] ans m-1-i m-1 m 1 i val i += 1 i 1 ra = uf.root(a) ra uf.root(a) uf.root uf root a rb = uf.root(b) rb uf.root(b) uf.root uf root b if ra==rb:
        pass
    else:
        val -= uf.size[ra] * uf.size[rb]
     ra==rb ra rb val -= uf.size[ra] * uf.size[rb] val uf.size[ra] * uf.size[rb] uf.size[ra] uf.size uf size ra uf.size[rb] uf.size uf size rb uf.connect(a,b) uf.connect uf connect a b write("\n".join(map(str, ans))) write "\n".join(map(str, ans)) "\n".join "\n" join map(str, ans) map str ans input = lambda : sys.stdin.readline().rstrip() lambda : sys.stdin.readline().rstrip() input val = n * (n-1) // 2 n * (n-1) // 2 val ans = [None] * m [None] * m ans ra = uf.root(a) uf.root(a) ra b = map(int, input().split()) map(int, input().split()) b i = 0 0 i ab = [None] * m [None] * m ab b -= 1 1 b class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
     class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
     UnionFindTree rb = uf.root(b) uf.root(b) rb n,m = map(int, input().split()) map(int, input().split()) n i += 1 1 i m = map(int, input().split()) map(int, input().split()) m val -= uf.size[ra] * uf.size[rb] uf.size[ra] * uf.size[rb] val a,b = map(int, input().split()) map(int, input().split()) a write = lambda x: sys.stdout.write(x+"\n") lambda x: sys.stdout.write(x+"\n") write a -= 1 1 a uf = UnionFindTree(n) UnionFindTree(n) uf
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
    
n,m = map(int, input().split())
uf = UnionFindTree(n)
ans = [None] * m
val = n * (n-1) // 2
ab = [None] * m
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ab[i] = (a,b)
i = 0
for a,b in ab[::-1]:
    ans[m-1-i] = val
    i += 1
    ra = uf.root(a)
    rb = uf.root(b)
    if ra==rb:
        pass
    else:
        val -= uf.size[ra] * uf.size[rb]
    uf.connect(a,b)
write("\n".join(map(str, ans)))
