#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int f[N][N];
int n, m, x, y, k;
int tl[N][N], tr[N][N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    while (k--) {
      scanf("%d%d", &x, &y);
      for (int j = x; j <= y; j++) tl[i][j] = x, tr[i][j] = y;
    }
  }
  for (int l = m; l; l--)
    for (int r = l; r <= m; r++)
      for (int t = l; t <= r; t++) {
        int tmp = 0;
        for (int i = 1; i <= n; i++) tmp += (l <= tl[i][t] && tr[i][t] <= r);
        f[l][r] = max(f[l][r], f[l][t - 1] + tmp * tmp + f[t + 1][r]);
      }
  printf("%d\n", f[1][m]);
}
