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