import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split())


class UnionFind(object):
    def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

es = [0] * M
for i in range(M):
    a, b = map(int, input().split())
    es[i] = (a - 1, b - 1)

u = UnionFind(N)
ans = []
pair = N * (N - 1) // 2
ans.append(pair)
for i in range(M - 1, -1, -1):
    a, b = es[i]
    if u.is_same(a, b):
        ans.append(pair)
        continue
    pair -= (u.get_size(a) * u.get_size(b))
    u.unite(a ,b)
    if pair < 0:
        pair = 0
    ans.append(pair)

for i in list(reversed(ans))[1:]:
    print(i) import sys sys import itertools itertools import time time import math math sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 from collections import defaultdict read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M class UnionFind(object):
    def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x] UnionFind def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

     __init__ i for i in range(n) for i in range(n) i range(n) range n for i in range(n) i self.link = [i for i in range(n)] self.link self link [i for i in range(n)] 1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 1 self.size = [1 for _ in range(n)] self.size self size [1 for _ in range(n)] self self n = 1 n 1 def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

     find if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
         self.link[x] == x self.link[x] self.link self link x x return x x self.link[x] = self.find(self.link[x]) self.link[x] self.link self link x self.find(self.link[x]) self.find self find self.link[x] self.link self link x return self.link[x] self.link[x] self.link self link x self self x x def is_same(self, x, y):
        return self.find(x) == self.find(y)

     is_same return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
     unite x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if x == y:
            return

         x == y x y return if self.size[x] < self.size[y]:
            x, y = y, x
         self.size[x] < self.size[y] self.size[x] self.size self size x self.size[y] self.size self size y x, y = y, x x y y x self.link[y] = x self.link[y] self.link self link 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 self x x y y def get_size(self, x):
        x = self.find(x)
        return self.size[x] get_size x = self.find(x) x self.find(x) self.find self find x return self.size[x] self.size[x] self.size self size x self self x x object es = [0] * M es [0] * M [0] 0 M for i in range(M):
    a, b = map(int, input().split())
    es[i] = (a - 1, b - 1) i range(M) range M a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b es[i] = (a - 1, b - 1) es[i] es i (a - 1, b - 1) a - 1 a 1 b - 1 b 1 u = UnionFind(N) u UnionFind(N) UnionFind N ans = [] ans [] pair = N * (N - 1) // 2 pair N * (N - 1) // 2 N * (N - 1) N N - 1 N 1 2 ans.append(pair) ans.append ans append pair for i in range(M - 1, -1, -1):
    a, b = es[i]
    if u.is_same(a, b):
        ans.append(pair)
        continue
    pair -= (u.get_size(a) * u.get_size(b))
    u.unite(a ,b)
    if pair < 0:
        pair = 0
    ans.append(pair) i range(M - 1, -1, -1) range M - 1 M 1 -1 -1 a, b = es[i] a es[i] es i b if u.is_same(a, b):
        ans.append(pair)
        continue
     u.is_same(a, b) u.is_same u is_same a b ans.append(pair) ans.append ans append pair continue pair -= (u.get_size(a) * u.get_size(b)) pair u.get_size(a) * u.get_size(b) u.get_size(a) u.get_size u get_size a u.get_size(b) u.get_size u get_size b u.unite(a ,b) u.unite u unite a b if pair < 0:
        pair = 0
     pair < 0 pair 0 pair = 0 pair 0 ans.append(pair) ans.append ans append pair for i in list(reversed(ans))[1:]:
    print(i) i list(reversed(ans))[1:] (reversed(ans)) list reversed(ans) reversed ans 1: 1 print(i) print i N, M = map(int, input().split()) map(int, input().split()) N pair -= (u.get_size(a) * u.get_size(b)) u.get_size(a) * u.get_size(b) pair readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines es = [0] * M [0] * M es pair = 0 0 pair class UnionFind(object):
    def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x] class UnionFind(object):
    def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x] UnionFind b = map(int, input().split()) map(int, input().split()) b read = sys.stdin.buffer.read sys.stdin.buffer.read read M = map(int, input().split()) map(int, input().split()) M b = es[i] es[i] b readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline u = UnionFind(N) UnionFind(N) u a, b = map(int, input().split()) map(int, input().split()) a pair = N * (N - 1) // 2 N * (N - 1) // 2 pair ans = [] [] ans a, b = es[i] es[i] a
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split())


class UnionFind(object):
    def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

es = [0] * M
for i in range(M):
    a, b = map(int, input().split())
    es[i] = (a - 1, b - 1)

u = UnionFind(N)
ans = []
pair = N * (N - 1) // 2
ans.append(pair)
for i in range(M - 1, -1, -1):
    a, b = es[i]
    if u.is_same(a, b):
        ans.append(pair)
        continue
    pair -= (u.get_size(a) * u.get_size(b))
    u.unite(a ,b)
    if pair < 0:
        pair = 0
    ans.append(pair)

for i in list(reversed(ans))[1:]:
    print(i)