#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
const long long MOD2 = (long long)1000000007 * (long long)1000000007;
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
vector<pair<int, int> > vp[(135)];
vector<int> pos[(135)];
int dp[(135)][(135)], f[(135)][(135)][(135)];
int cal(int l, int r) {
  if (r < l) return 0;
  int& tmp = dp[l][r];
  if (tmp != -1) return tmp;
  for (int k = l; k <= r; k++) {
    int zz = cal(l, k - 1) + cal(k + 1, r) + f[l][r][k] * (f[l][r][k]);
    maxtt(tmp, zz);
  }
  return tmp;
}
int b[(135)];
void init() {
  memset(dp, -1, sizeof dp);
  vector<int> idx(n + 1, 0);
  for (int(l) = 1; (l) <= (int)(m); (l)++) {
    for (int(i) = 1; (i) <= (int)(n); (i)++)
      while (idx[i] < vp[i].size() && vp[i][idx[i]].first < l) idx[i]++;
    for (int(i) = 1; (i) <= (int)(m); (i)++) pos[i].clear();
    for (int(i) = 1; (i) <= (int)(n); (i)++) {
      for (int j = idx[i]; j < vp[i].size(); j++) {
        assert(vp[i][j].first >= l);
        pos[vp[i][j].second].push_back(vp[i][j].first);
      }
    }
    vector<int> A(m + 2, 0);
    for (int r = l; r <= m; r++) {
      for (int z : pos[r]) {
        A[z]++;
        A[r + 1]--;
      }
      int pre = 0;
      for (int k = l; k <= r; k++) {
        pre += A[k];
        f[l][r][k] = pre;
      }
    }
  }
}
void fmain(int tid) {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%d", &k);
    for (int(j) = 0; (j) < (int)(k); (j)++) {
      int l, r;
      scanf("%d%d", &l, &r);
      vp[i].push_back({l, r});
    }
  }
  init();
  int ans = cal(1, m);
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
