class UnionFind():
    def __init__(self, n):
        self.size = n
        self.data = [-1 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def __len__(self):
        return self.size

    def root(self, i):
        """0 <= i < n"""
        if self.data[i] < 0:
            return i
        self.data[i] = self.root(self.data[i])
        return self.data[i]

    def connected(self, i, j):
        return self.root(i) == self.root(j)

    def groupsize(self, i):
        return self.sizes[self.root(i)]

    def roots(self):
        """O(n)"""
        return [i for i, v in enumerate(self.data) if v < 0]

    def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j]


def nC2(n):
    return n * (n - 1) // 2


N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b))

unconv = nC2(N)
revans = []
uf = UnionFind(N + 1)

for a, b in reversed(AB):
    revans.append(unconv)
    if uf.connected(a, b):
        continue
    unconv += nC2(uf.groupsize(a))
    unconv += nC2(uf.groupsize(b))
    uf.unite(a, b)
    unconv -= nC2(uf.groupsize(a))

for v in reversed(revans):
    print(v) class UnionFind():
    def __init__(self, n):
        self.size = n
        self.data = [-1 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def __len__(self):
        return self.size

    def root(self, i):
        """0 <= i < n"""
        if self.data[i] < 0:
            return i
        self.data[i] = self.root(self.data[i])
        return self.data[i]

    def connected(self, i, j):
        return self.root(i) == self.root(j)

    def groupsize(self, i):
        return self.sizes[self.root(i)]

    def roots(self):
        """O(n)"""
        return [i for i, v in enumerate(self.data) if v < 0]

    def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j] UnionFind def __init__(self, n):
        self.size = n
        self.data = [-1 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

     __init__ self.size = n self.size self size n -1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) -1 self.data = [-1 for _ in range(n)] self.data self data [-1 for _ in range(n)] 1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 1 self.sizes = [1 for _ in range(n)] self.sizes self sizes [1 for _ in range(n)] self self n n def __len__(self):
        return self.size

     __len__ return self.size self.size self size self self def root(self, i):
        """0 <= i < n"""
        if self.data[i] < 0:
            return i
        self.data[i] = self.root(self.data[i])
        return self.data[i]

     root """0 <= i < n""" if self.data[i] < 0:
            return i
         self.data[i] < 0 self.data[i] self.data self data i 0 return i i self.data[i] = self.root(self.data[i]) self.data[i] self.data self data i self.root(self.data[i]) self.root self root self.data[i] self.data self data i return self.data[i] self.data[i] self.data self data i self self i i def connected(self, i, j):
        return self.root(i) == self.root(j)

     connected return self.root(i) == self.root(j) self.root(i) == self.root(j) self.root(i) self.root self root i self.root(j) self.root self root j self self i i j j def groupsize(self, i):
        return self.sizes[self.root(i)]

     groupsize return self.sizes[self.root(i)] self.sizes[self.root(i)] self.sizes self sizes self.root(i) self.root self root i self self i i def roots(self):
        """O(n)"""
        return [i for i, v in enumerate(self.data) if v < 0]

     roots """O(n)""" i for i, v in enumerate(self.data) if v < 0 for i, v in enumerate(self.data) if v < 0 i v enumerate(self.data) enumerate self.data self data v < 0 v 0 if v < 0 i return [i for i, v in enumerate(self.data) if v < 0] [i for i, v in enumerate(self.data) if v < 0] self self def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j] unite i = self.root(i) i self.root(i) self.root self root i j = self.root(j) j self.root(j) self.root self root j if i == j:
            return
         i == j i j return if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j] (-self.data[i]) < (-self.data[j]) -self.data[i] self.data[i] self.data self data i -self.data[j] self.data[j] self.data self data j self.data[i] = j self.data[i] self.data self data i j self.sizes[j] += self.sizes[i] self.sizes[j] self.sizes self sizes j self.sizes[i] self.sizes self sizes i elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
         (-self.data[i]) > (-self.data[j]) -self.data[i] self.data[i] self.data self data i -self.data[j] self.data[j] self.data self data j self.data[j] = i self.data[j] self.data self data j i self.sizes[i] += self.sizes[j] self.sizes[i] self.sizes self sizes i self.sizes[j] self.sizes self sizes j self.data[i] += -1 self.data[i] self.data self data i -1 self.data[j] = i self.data[j] self.data self data j i self.sizes[i] += self.sizes[j] self.sizes[i] self.sizes self sizes i self.sizes[j] self.sizes self sizes j self self i i j j def nC2(n):
    return n * (n - 1) // 2 nC2 return n * (n - 1) // 2 n * (n - 1) // 2 n * (n - 1) n n - 1 n 1 2 n n N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M AB = [] AB [] for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b)) _ range(M) range M a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b AB.append((a, b)) AB.append AB append (a, b) a b unconv = nC2(N) unconv nC2(N) nC2 N revans = [] revans [] uf = UnionFind(N + 1) uf UnionFind(N + 1) UnionFind N + 1 N 1 for a, b in reversed(AB):
    revans.append(unconv)
    if uf.connected(a, b):
        continue
    unconv += nC2(uf.groupsize(a))
    unconv += nC2(uf.groupsize(b))
    uf.unite(a, b)
    unconv -= nC2(uf.groupsize(a)) a b reversed(AB) reversed AB revans.append(unconv) revans.append revans append unconv if uf.connected(a, b):
        continue
     uf.connected(a, b) uf.connected uf connected a b continue unconv += nC2(uf.groupsize(a)) unconv nC2(uf.groupsize(a)) nC2 uf.groupsize(a) uf.groupsize uf groupsize a unconv += nC2(uf.groupsize(b)) unconv nC2(uf.groupsize(b)) nC2 uf.groupsize(b) uf.groupsize uf groupsize b uf.unite(a, b) uf.unite uf unite a b unconv -= nC2(uf.groupsize(a)) unconv nC2(uf.groupsize(a)) nC2 uf.groupsize(a) uf.groupsize uf groupsize a for v in reversed(revans):
    print(v) v reversed(revans) reversed revans print(v) print v revans = [] [] revans uf = UnionFind(N + 1) UnionFind(N + 1) uf M = map(int, input().split()) map(int, input().split()) M unconv += nC2(uf.groupsize(b)) nC2(uf.groupsize(b)) unconv AB = [] [] AB N, M = map(int, input().split()) map(int, input().split()) N a, b = map(int, input().split()) map(int, input().split()) a class UnionFind():
    def __init__(self, n):
        self.size = n
        self.data = [-1 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def __len__(self):
        return self.size

    def root(self, i):
        """0 <= i < n"""
        if self.data[i] < 0:
            return i
        self.data[i] = self.root(self.data[i])
        return self.data[i]

    def connected(self, i, j):
        return self.root(i) == self.root(j)

    def groupsize(self, i):
        return self.sizes[self.root(i)]

    def roots(self):
        """O(n)"""
        return [i for i, v in enumerate(self.data) if v < 0]

    def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j] class UnionFind():
    def __init__(self, n):
        self.size = n
        self.data = [-1 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def __len__(self):
        return self.size

    def root(self, i):
        """0 <= i < n"""
        if self.data[i] < 0:
            return i
        self.data[i] = self.root(self.data[i])
        return self.data[i]

    def connected(self, i, j):
        return self.root(i) == self.root(j)

    def groupsize(self, i):
        return self.sizes[self.root(i)]

    def roots(self):
        """O(n)"""
        return [i for i, v in enumerate(self.data) if v < 0]

    def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j] UnionFind b = map(int, input().split()) map(int, input().split()) b unconv -= nC2(uf.groupsize(a)) nC2(uf.groupsize(a)) unconv def nC2(n):
    return n * (n - 1) // 2 def nC2(n):
    return n * (n - 1) // 2 nC2 unconv = nC2(N) nC2(N) unconv unconv += nC2(uf.groupsize(a)) nC2(uf.groupsize(a)) unconv
class UnionFind():
    def __init__(self, n):
        self.size = n
        self.data = [-1 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def __len__(self):
        return self.size

    def root(self, i):
        """0 <= i < n"""
        if self.data[i] < 0:
            return i
        self.data[i] = self.root(self.data[i])
        return self.data[i]

    def connected(self, i, j):
        return self.root(i) == self.root(j)

    def groupsize(self, i):
        return self.sizes[self.root(i)]

    def roots(self):
        """O(n)"""
        return [i for i, v in enumerate(self.data) if v < 0]

    def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j]


def nC2(n):
    return n * (n - 1) // 2


N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b))

unconv = nC2(N)
revans = []
uf = UnionFind(N + 1)

for a, b in reversed(AB):
    revans.append(unconv)
    if uf.connected(a, b):
        continue
    unconv += nC2(uf.groupsize(a))
    unconv += nC2(uf.groupsize(b))
    uf.unite(a, b)
    unconv -= nC2(uf.groupsize(a))

for v in reversed(revans):
    print(v)
