#include <bits/stdc++.h>
using namespace std;
const int N = 110, mod = 1e9 + 7, INF = 0x3f3f3f3f;
const double eps = 1e-6;
int n, m;
int a[N][N], b[N][N], f[N][N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int l, r;
      scanf("%d%d", &l, &r);
      for (int j = l; j <= r; j++) a[i][j] = l, b[i][j] = r;
    }
  }
  for (int len = 1; len <= m; len++) {
    for (int l = 1; l + len - 1 <= m; l++) {
      int r = l + len - 1;
      for (int i = l; i <= r; i++) {
        int sum = 0;
        for (int j = 1; j <= n; j++)
          if (a[j][i] >= l && b[j][i] <= r) sum++;
        f[l][r] = max(f[l][r], f[l][i - 1] + sum * sum + f[i + 1][r]);
      }
    }
  }
  printf("%d\n", f[1][m]);
  return 0;
}
