#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int msbp(int x) { return 31 - __builtin_clz(x); }
inline int msb(int x) { return 1 << msbp(x); }
const int INF = 0x3f3f3f3f;
const int N = 1e2 + 10;
int n, m, dp[N][N], lef[N][N], rig[N][N];
long long ans;
int rec(int l, int r) {
  if (l > r) return 0;
  int& memo = dp[l][r];
  if (memo != -1) return memo;
  int res = 0;
  for (int j = (l); j <= (r); ++j) {
    int cur = 0;
    for (int i = (1); i <= (n); ++i) {
      if (lef[i][j] >= l && rig[i][j] <= r) {
        ++cur;
      }
    }
    res = max(res, cur * cur + rec(l, j - 1) + rec(j + 1, r));
  }
  return memo = res;
}
signed main() {
  ios::sync_with_stdio(false);
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = (1); i <= (n); ++i) {
    int k;
    cin >> k;
    for (int _ = 0; _ < (k); ++_) {
      int l, r;
      cin >> l >> r;
      for (int j = (l); j <= (r); ++j) {
        lef[i][j] = l;
        rig[i][j] = r;
      }
    }
  }
  cout << rec(1, m) << endl;
  return 0;
}
