#include <bits/stdc++.h>
using namespace std;
pair<int, int> grid[105][105];
int dp[105][105];
int n, m;
int sol(int i, int j) {
  if (i > j) return 0;
  int &ret = dp[i][j];
  if (~ret) return ret;
  ret = 0;
  for (int k = i; k <= j; k++) {
    int cnt = 0;
    for (int x = 0; x < n; x++) {
      if (grid[x][k].first >= i && grid[x][k].second <= j) cnt++;
    }
    int cur = cnt * cnt + sol(i, k - 1) + sol(k + 1, j);
    ret = max(ret, cur);
  }
  return ret;
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      for (int k = l; k <= r; k++) grid[i][k] = {l, r};
    }
  }
  memset(dp, -1, sizeof dp);
  cout << sol(0, m - 1) << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
