#include <bits/stdc++.h>
using namespace std;
int f[105][105], L[105][105], R[105][105], n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    for (int op = 1; op <= x; op++) {
      int l, r;
      scanf("%d%d", &l, &r);
      for (int j = l; j <= r; j++) L[j][i] = l, R[j][i] = r;
    }
  }
  for (int len = 1; len <= m; len++) {
    for (int l = 1; l <= m - len + 1; l++) {
      int r = l + len - 1;
      for (int k = l; k <= r; k++) {
        int sum = 0;
        for (int w = 1; w <= n; w++) sum += (L[k][w] >= l && R[k][w] <= r);
        f[l][r] = max(f[l][r], f[l][k - 1] + f[k + 1][r] + sum * sum);
      }
    }
  }
  printf("%d\n", f[1][m]);
  return 0;
}
