#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[1000][1000];
int dp[1000][1000];
int n, m, k, l, r;
int calc(int l, int r, int i) {
  int cnt = 0;
  for (int j = 0; j < n; ++j)
    if (a[j][i].first >= l && a[j][i].second <= r) ++cnt;
  return cnt;
}
int solve(int l, int r) {
  if (~dp[l][r]) return dp[l][r];
  if (l > r) return 0;
  int res = 0;
  for (int i = l; i <= r; ++i) {
    int num = calc(l, r, i);
    res = max(res, solve(l, i - 1) + num * num + solve(i + 1, r));
  }
  return dp[l][r] = res;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> l >> r;
      for (int x = l; x <= r; ++x) a[i][x] = {l, r};
    }
  }
  cout << solve(1, m);
}
