#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
using namespace std;
inline void MAX(int &a, int b) {
  if (b > a) a = b;
}
int n, m;
int tol[121][121], tor[121][121];
int f[121][121];
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) {
    int k;
    read(k);
    for (int j = 1; j <= k; ++j) {
      int l, r;
      read(l);
      read(r);
      for (int u = l; u <= r; ++u) tol[i][u] = l, tor[i][u] = r;
    }
  }
  for (int len = 1; len <= m; ++len) {
    for (int l = 1, r = len; r <= m; ++l, ++r) {
      for (int mid = l; mid <= r; ++mid) {
        int ct = 0;
        for (int h = 1; h <= n; ++h) {
          if (tor[h][mid] <= r && tol[h][mid] >= l) ++ct;
        }
        MAX(f[l][r], f[l][mid - 1] + f[mid + 1][r] + ct * ct);
      }
    }
  }
  printf("%d\n", f[1][m]);
  return 0;
}
