#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 105;
int n, m;
int lef[N][N], rig[N][N];
int dp[N][N];
int f(int l, int r) {
  if (r < l) return 0;
  int &ans = dp[l][r];
  if (~ans) return ans;
  ans = 0;
  for (int j = l; j <= r; j++) {
    int tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += l <= lef[j][i] and rig[j][i] <= r;
    }
    ans = max(ans, tmp * tmp + f(l, j - 1) + f(j + 1, r));
  }
  return ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int sz;
    scanf("%d", &sz);
    while (sz--) {
      int l, r;
      scanf("%d %d", &l, &r);
      l--, r--;
      for (int j = l; j <= r; j++) {
        lef[j][i] = l;
        rig[j][i] = r;
      }
    }
  }
  printf("%d\n", f(0, m - 1));
}
