#include <bits/stdc++.h>
using namespace std;
const int M = 105;
int L[M][M], R[M][M];
int n, m, f[M][M];
inline void ckmax(int& x, int y) { x < y ? (x = y) : 0; }
int calc(int k, int l, int r) {
  int res = 0;
  for (int i = 1; i <= n; i++) res += (L[i][k] >= l && R[i][k] <= r);
  return res * res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, N; i <= n; i++) {
    scanf("%d", &N);
    for (int j = 1, x, y; j <= N; j++) {
      scanf("%d%d", &x, &y);
      for (int k = x; k <= y; k++) L[i][k] = x, R[i][k] = y;
    }
  }
  for (int len = 1; len <= m; len++)
    for (int i = 1; i <= m; i++) {
      int j = i + len - 1;
      for (int k = i; k <= j; k++)
        ckmax(f[i][j], f[i][k - 1] + f[k + 1][j] + calc(k, i, j));
    }
  printf("%d", f[1][m]);
  return 0;
}
