#include <bits/stdc++.h>
using namespace std;
const int MAXN = 130;
int n, m;
int F[MAXN][MAXN];
int A[MAXN][MAXN], B[MAXN][MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m + 1; ++i) F[i][i - 1] = 0;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    int u;
    scanf("%d", &u);
    for (int j = 1; j <= u; ++j) {
      int L, R;
      scanf("%d%d", &L, &R);
      for (int k = L; k <= R; ++k) {
        A[i][k] = L;
        B[i][k] = R;
      }
    }
  }
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= m - i + 1; ++j) {
      int L = j, R = i + j - 1;
      for (int k = L; k <= R; ++k) {
        int tot = 0;
        for (int l = 1; l <= n; ++l)
          if (B[l][k] <= R && A[l][k] >= L) tot++;
        F[L][R] = max(F[L][R], F[L][k - 1] + F[k + 1][R] + tot * tot);
      }
    }
  cout << F[1][m] << endl;
  return 0;
}
