class MergeFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]

    def find(self, a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]

    def merge(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        if self.size[a] < self.size[b]:
            a, b = b, a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
        self.lista[b] = []

    def set_size(self, a):
        return self.size[self.find(a)]

    def __len__(self):
        return self.num_sets


n,m=map(int,input().strip().split(" "))
ar=[]
for _ in range(m):
    ar.append((int(i) - 1 for i in input().strip().split(" ")))
ans=[]

d=MergeFind(n)

for i in range(m-1,-1,-1):
    a,b=ar[i]
    A=d.find(a)
    B=d.find(b)
    if A==B:
        ans.append(0)
    else:
        ans.append(d.size[A]*d.size[B])
        d.merge(a,b)
fin=[ans[-1]]
for i in range(m-2,-1,-1):
    fin.append(fin[-1]+ans[i])
for i in fin:
    print(i)
 class MergeFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]

    def find(self, a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]

    def merge(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        if self.size[a] < self.size[b]:
            a, b = b, a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
        self.lista[b] = []

    def set_size(self, a):
        return self.size[self.find(a)]

    def __len__(self):
        return self.num_sets MergeFind def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]

     __init__ 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.num_sets = n self.num_sets self num_sets n [_] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [_] _ self.lista = [[_] for _ in range(n)] self.lista self lista [[_] for _ in range(n)] self self n n def find(self, a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]

     find to_update = [] to_update [] while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
         a != self.parent[a] a self.parent[a] self.parent self parent a to_update.append(a) to_update.append to_update append a a = self.parent[a] a self.parent[a] self.parent self parent a for b in to_update:
            self.parent[b] = a
         b to_update self.parent[b] = a self.parent[b] self.parent self parent b a return self.parent[a] self.parent[a] self.parent self parent a self self a a def merge(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        if self.size[a] < self.size[b]:
            a, b = b, a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
        self.lista[b] = []

     merge a = self.find(a) a self.find(a) self.find self find a b = self.find(b) b self.find(b) self.find self find b if a == b:
            return
         a == b a b return if self.size[a] < self.size[b]:
            a, b = b, a
         self.size[a] < self.size[b] self.size[a] self.size self size a self.size[b] self.size self size b a, b = b, a a b b a self.num_sets -= 1 self.num_sets self num_sets 1 self.parent[b] = a self.parent[b] self.parent self parent b a self.size[a] += self.size[b] self.size[a] self.size self size a self.size[b] self.size self size b self.lista[a] += self.lista[b] self.lista[a] self.lista self lista a self.lista[b] self.lista self lista b self.lista[b] = [] self.lista[b] self.lista self lista b [] self self a a b b def set_size(self, a):
        return self.size[self.find(a)]

     set_size return self.size[self.find(a)] self.size[self.find(a)] self.size self size self.find(a) self.find self find a self self a a def __len__(self):
        return self.num_sets __len__ return self.num_sets self.num_sets self num_sets self self n,m=map(int,input().strip().split(" ")) n map(int,input().strip().split(" ")) map int input().strip().split(" ") ().strip().split ().strip() ().strip () input strip split " " m ar=[] ar [] for _ in range(m):
    ar.append((int(i) - 1 for i in input().strip().split(" "))) _ range(m) range m int(i) - 1 for i in input().strip().split(" ") for i in input().strip().split(" ") i input().strip().split(" ") ().strip().split ().strip() ().strip () input strip split " " for i in input().strip().split(" ") int(i) - 1 int(i) int i 1 ar.append((int(i) - 1 for i in input().strip().split(" "))) ar.append ar append (int(i) - 1 for i in input().strip().split(" ")) ans=[] ans [] d=MergeFind(n) d MergeFind(n) MergeFind n for i in range(m-1,-1,-1):
    a,b=ar[i]
    A=d.find(a)
    B=d.find(b)
    if A==B:
        ans.append(0)
    else:
        ans.append(d.size[A]*d.size[B])
        d.merge(a,b) i range(m-1,-1,-1) range m-1 m 1 -1 -1 a,b=ar[i] a ar[i] ar i b A=d.find(a) A d.find(a) d.find d find a B=d.find(b) B d.find(b) d.find d find b if A==B:
        ans.append(0)
    else:
        ans.append(d.size[A]*d.size[B])
        d.merge(a,b) A==B A B ans.append(0) ans.append ans append 0 ans.append(d.size[A]*d.size[B]) ans.append ans append d.size[A]*d.size[B] d.size[A] d.size d size A d.size[B] d.size d size B d.merge(a,b) d.merge d merge a b fin=[ans[-1]] fin [ans[-1]] ans[-1] ans -1 for i in range(m-2,-1,-1):
    fin.append(fin[-1]+ans[i]) i range(m-2,-1,-1) range m-2 m 2 -1 -1 fin.append(fin[-1]+ans[i]) fin.append fin append fin[-1]+ans[i] fin[-1] fin -1 ans[i] ans i for i in fin:
    print(i) i fin print(i) print i ar=[] [] ar d=MergeFind(n) MergeFind(n) d A=d.find(a) d.find(a) A fin=[ans[-1]] [ans[-1]] fin m=map(int,input().strip().split(" ")) map(int,input().strip().split(" ")) m b=ar[i] ar[i] b a,b=ar[i] ar[i] a n,m=map(int,input().strip().split(" ")) map(int,input().strip().split(" ")) n class MergeFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]

    def find(self, a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]

    def merge(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        if self.size[a] < self.size[b]:
            a, b = b, a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
        self.lista[b] = []

    def set_size(self, a):
        return self.size[self.find(a)]

    def __len__(self):
        return self.num_sets class MergeFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]

    def find(self, a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]

    def merge(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        if self.size[a] < self.size[b]:
            a, b = b, a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
        self.lista[b] = []

    def set_size(self, a):
        return self.size[self.find(a)]

    def __len__(self):
        return self.num_sets MergeFind ans=[] [] ans B=d.find(b) d.find(b) B
class MergeFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]

    def find(self, a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]

    def merge(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        if self.size[a] < self.size[b]:
            a, b = b, a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
        self.lista[b] = []

    def set_size(self, a):
        return self.size[self.find(a)]

    def __len__(self):
        return self.num_sets


n,m=map(int,input().strip().split(" "))
ar=[]
for _ in range(m):
    ar.append((int(i) - 1 for i in input().strip().split(" ")))
ans=[]

d=MergeFind(n)

for i in range(m-1,-1,-1):
    a,b=ar[i]
    A=d.find(a)
    B=d.find(b)
    if A==B:
        ans.append(0)
    else:
        ans.append(d.size[A]*d.size[B])
        d.merge(a,b)
fin=[ans[-1]]
for i in range(m-2,-1,-1):
    fin.append(fin[-1]+ans[i])
for i in fin:
    print(i)

