#include <bits/stdc++.h>
using namespace std;
long long DP[105][105] = {0};
bool have[105][105] = {0};
long long con[105][105];
long long N, M;
vector<pair<int, int> > all[105];
long long F(long long l, long long r) {
  long long t = 0, i, j;
  if (l > r) return 0;
  if (have[l][r]) return DP[l][r];
  have[l][r] = 1;
  for (i = l; i <= r; i++) {
    t = 0;
    for (j = 1; j <= N; j++)
      if (all[j][con[j][i]].first >= l && all[j][con[j][i]].second <= r) t++;
    DP[l][r] = max(DP[l][r], F(l, i - 1) + F(i + 1, r) + t * t);
  }
  return DP[l][r];
}
int main() {
  long long i, j, k, t, l, r;
  scanf("%lld %lld", &N, &M);
  for (i = 1; i <= N; i++) {
    scanf("%lld", &t);
    for (j = 0; j < t; j++) {
      scanf("%lld %lld", &l, &r);
      all[i].push_back(make_pair(l, r));
      for (k = l; k <= r; k++) con[i][k] = j;
    }
  }
  printf("%lld\n", F(1, M));
  return 0;
}
