import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes

        # self.parents[x] < 0 の時，xが根である．
        # また，xが根の時，(-1) * (同一グループの要素数) が格納されるようになる.
        self.parents = [-1] * n_nodes

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        # 常にxの方が要素数が多くなるように，スワップする
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        # 要素数の少ない方のグループを，要素数が多い方の木に貼る．
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def get_size(self, x):
        return -self.parents[self.find(x)]

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

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_parent_list(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}


def main():
    N, M = map(int, input().split())
    tree = UnionFind(N)

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

    # 行き来できる島の数を記録
    cnt = [0]
    for i in range(M):
        a, b = ab[i]
        a -= 1
        b -= 1
        if tree.is_same(a, b):
            cnt.append(cnt[-1])
            continue

        c = cnt[-1]
        a_size = tree.get_size(a)
        b_size = tree.get_size(b)
        c -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2

        tree.unite(a, b)
        size = tree.get_size(a)
        c += size * (size - 1) // 2
        cnt.append(c)

    cnt.reverse()
    orig = cnt[0]
    for c in cnt[1:]:
        print(orig - c)


if __name__ == "__main__":
    main() import sys sys sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 INF = float("inf") INF float("inf") float "inf" MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 def input():
    return sys.stdin.readline().strip() input return sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes

        # self.parents[x] < 0 の時，xが根である．
        # また，xが根の時，(-1) * (同一グループの要素数) が格納されるようになる.
        self.parents = [-1] * n_nodes

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        # 常にxの方が要素数が多くなるように，スワップする
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        # 要素数の少ない方のグループを，要素数が多い方の木に貼る．
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def get_size(self, x):
        return -self.parents[self.find(x)]

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

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_parent_list(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()} UnionFind def __init__(self, n_nodes):
        self.n_nodes = n_nodes

        # self.parents[x] < 0 の時，xが根である．
        # また，xが根の時，(-1) * (同一グループの要素数) が格納されるようになる.
        self.parents = [-1] * n_nodes

     __init__ self.n_nodes = n_nodes self.n_nodes self n_nodes n_nodes self.parents = [-1] * n_nodes self.parents self parents [-1] * n_nodes [-1] -1 n_nodes self self n_nodes n_nodes def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

     find if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

     self.parents[x] < 0 self.parents[x] self.parents self parents x 0 return x x self.parents[x] = self.find(self.parents[x]) self.parents[x] self.parents self parents x self.find(self.parents[x]) self.find self find self.parents[x] self.parents self parents x return self.parents[x] self.parents[x] self.parents self parents x self self x x def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        # 常にxの方が要素数が多くなるように，スワップする
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        # 要素数の少ない方のグループを，要素数が多い方の木に貼る．
        self.parents[x] += self.parents[y]
        self.parents[y] = x

     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の方が要素数が多くなるように，スワップする
         x == y x y return if self.parents[x] > self.parents[y]:
            x, y = y, x

        # 要素数の少ない方のグループを，要素数が多い方の木に貼る．
         self.parents[x] > self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y x, y = y, x x y y x self.parents[x] += self.parents[y] self.parents[x] self.parents self parents x self.parents[y] self.parents self parents y self.parents[y] = x self.parents[y] self.parents self parents y x self self x x y y def get_size(self, x):
        return -self.parents[self.find(x)]

     get_size return -self.parents[self.find(x)] -self.parents[self.find(x)] self.parents[self.find(x)] self.parents self parents self.find(x) self.find self find 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 get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

     get_members parent = self.find(x) parent self.find(x) self.find self find x i for i in range(self.n_nodes) if self.find(i) == parent for i in range(self.n_nodes) if self.find(i) == parent i range(self.n_nodes) range self.n_nodes self n_nodes self.find(i) == parent self.find(i) self.find self find i parent if self.find(i) == parent i return [i for i in range(self.n_nodes) if self.find(i) == parent] [i for i in range(self.n_nodes) if self.find(i) == parent] self self x x def get_parent_list(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

     get_parent_list i for i, x in enumerate(self.parents) if x < 0 for i, x in enumerate(self.parents) if x < 0 i x enumerate(self.parents) enumerate self.parents self parents x < 0 x 0 if x < 0 i return [i for i, x in enumerate(self.parents) if x < 0] [i for i, x in enumerate(self.parents) if x < 0] self self def get_n_groups(self):
        return len(self.get_parent_list())

     get_n_groups return len(self.get_parent_list()) len(self.get_parent_list()) len self.get_parent_list() self.get_parent_list self get_parent_list self self def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()} get_members_dict par: self.get_members(par) for par in self.get_parent_list() for par in self.get_parent_list() par self.get_parent_list() self.get_parent_list self get_parent_list for par in self.get_parent_list() par self.get_members(par) self.get_members self get_members par return {par: self.get_members(par) for par in self.get_parent_list()} {par: self.get_members(par) for par in self.get_parent_list()} self self def main():
    N, M = map(int, input().split())
    tree = UnionFind(N)

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

    # 行き来できる島の数を記録
    cnt = [0]
    for i in range(M):
        a, b = ab[i]
        a -= 1
        b -= 1
        if tree.is_same(a, b):
            cnt.append(cnt[-1])
            continue

        c = cnt[-1]
        a_size = tree.get_size(a)
        b_size = tree.get_size(b)
        c -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2

        tree.unite(a, b)
        size = tree.get_size(a)
        c += size * (size - 1) // 2
        cnt.append(c)

    cnt.reverse()
    orig = cnt[0]
    for c in cnt[1:]:
        print(orig - c) main N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M tree = UnionFind(N) tree UnionFind(N) UnionFind N 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 ab.reverse() ab.reverse ab reverse cnt = [0] cnt [0] 0 for i in range(M):
        a, b = ab[i]
        a -= 1
        b -= 1
        if tree.is_same(a, b):
            cnt.append(cnt[-1])
            continue

        c = cnt[-1]
        a_size = tree.get_size(a)
        b_size = tree.get_size(b)
        c -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2

        tree.unite(a, b)
        size = tree.get_size(a)
        c += size * (size - 1) // 2
        cnt.append(c)

     i range(M) range M a, b = ab[i] a ab[i] ab i b a -= 1 a 1 b -= 1 b 1 if tree.is_same(a, b):
            cnt.append(cnt[-1])
            continue

         tree.is_same(a, b) tree.is_same tree is_same a b cnt.append(cnt[-1]) cnt.append cnt append cnt[-1] cnt -1 continue c = cnt[-1] c cnt[-1] cnt -1 a_size = tree.get_size(a) a_size tree.get_size(a) tree.get_size tree get_size a b_size = tree.get_size(b) b_size tree.get_size(b) tree.get_size tree get_size b c -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2 c a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2 a_size * (a_size - 1) // 2 a_size * (a_size - 1) a_size a_size - 1 a_size 1 2 b_size * (b_size - 1) // 2 b_size * (b_size - 1) b_size b_size - 1 b_size 1 2 tree.unite(a, b) tree.unite tree unite a b size = tree.get_size(a) size tree.get_size(a) tree.get_size tree get_size a c += size * (size - 1) // 2 c size * (size - 1) // 2 size * (size - 1) size size - 1 size 1 2 cnt.append(c) cnt.append cnt append c cnt.reverse() cnt.reverse cnt reverse orig = cnt[0] orig cnt[0] cnt 0 for c in cnt[1:]:
        print(orig - c) c cnt[1:] cnt 1: 1 print(orig - c) print orig - c orig c if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes

        # self.parents[x] < 0 の時，xが根である．
        # また，xが根の時，(-1) * (同一グループの要素数) が格納されるようになる.
        self.parents = [-1] * n_nodes

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        # 常にxの方が要素数が多くなるように，スワップする
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        # 要素数の少ない方のグループを，要素数が多い方の木に貼る．
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def get_size(self, x):
        return -self.parents[self.find(x)]

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

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_parent_list(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()} class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes

        # self.parents[x] < 0 の時，xが根である．
        # また，xが根の時，(-1) * (同一グループの要素数) が格納されるようになる.
        self.parents = [-1] * n_nodes

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        # 常にxの方が要素数が多くなるように，スワップする
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        # 要素数の少ない方のグループを，要素数が多い方の木に貼る．
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def get_size(self, x):
        return -self.parents[self.find(x)]

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

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_parent_list(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()} UnionFind INF = float("inf") float("inf") INF MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD def main():
    N, M = map(int, input().split())
    tree = UnionFind(N)

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

    # 行き来できる島の数を記録
    cnt = [0]
    for i in range(M):
        a, b = ab[i]
        a -= 1
        b -= 1
        if tree.is_same(a, b):
            cnt.append(cnt[-1])
            continue

        c = cnt[-1]
        a_size = tree.get_size(a)
        b_size = tree.get_size(b)
        c -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2

        tree.unite(a, b)
        size = tree.get_size(a)
        c += size * (size - 1) // 2
        cnt.append(c)

    cnt.reverse()
    orig = cnt[0]
    for c in cnt[1:]:
        print(orig - c) def main():
    N, M = map(int, input().split())
    tree = UnionFind(N)

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

    # 行き来できる島の数を記録
    cnt = [0]
    for i in range(M):
        a, b = ab[i]
        a -= 1
        b -= 1
        if tree.is_same(a, b):
            cnt.append(cnt[-1])
            continue

        c = cnt[-1]
        a_size = tree.get_size(a)
        b_size = tree.get_size(b)
        c -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2

        tree.unite(a, b)
        size = tree.get_size(a)
        c += size * (size - 1) // 2
        cnt.append(c)

    cnt.reverse()
    orig = cnt[0]
    for c in cnt[1:]:
        print(orig - c) main def input():
    return sys.stdin.readline().strip() def input():
    return sys.stdin.readline().strip() input
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes

        # self.parents[x] < 0 の時，xが根である．
        # また，xが根の時，(-1) * (同一グループの要素数) が格納されるようになる.
        self.parents = [-1] * n_nodes

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        # 常にxの方が要素数が多くなるように，スワップする
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        # 要素数の少ない方のグループを，要素数が多い方の木に貼る．
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def get_size(self, x):
        return -self.parents[self.find(x)]

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

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_parent_list(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}


def main():
    N, M = map(int, input().split())
    tree = UnionFind(N)

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

    # 行き来できる島の数を記録
    cnt = [0]
    for i in range(M):
        a, b = ab[i]
        a -= 1
        b -= 1
        if tree.is_same(a, b):
            cnt.append(cnt[-1])
            continue

        c = cnt[-1]
        a_size = tree.get_size(a)
        b_size = tree.get_size(b)
        c -= a_size * (a_size - 1) // 2 + b_size * (b_size - 1) // 2

        tree.unite(a, b)
        size = tree.get_size(a)
        c += size * (size - 1) // 2
        cnt.append(c)

    cnt.reverse()
    orig = cnt[0]
    for c in cnt[1:]:
        print(orig - c)


if __name__ == "__main__":
    main()
