#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> allint[105];
long long dp[105][105];
long long go(int from, int to) {
  if (from > to) return 0;
  if (dp[from][to] != -1) return dp[from][to];
  vector<vector<pair<int, int>>> currint(n);
  for (int i = 0; i < n; ++i)
    for (pair<int, int> &x : allint[i])
      if (x.first >= from && x.second <= to) currint[i].push_back(x);
  long long ans = 0;
  for (int j = from; j <= to; ++j) {
    long long curr = 0;
    for (int i = 0; i < n; ++i) {
      curr += currint[i].size() > 0 && currint[i].front().first <= j &&
              currint[i].back().second >= j;
    }
    long long val = go(from, j - 1) + curr * curr + go(j + 1, to);
    ans = max(ans, val);
  }
  return dp[from][to] = ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    while (k--) {
      int l, r;
      cin >> l >> r;
      --l, --r;
      allint[i].push_back({l, r});
    }
  }
  memset(dp, 255, sizeof(dp));
  cout << go(0, m - 1) << "\n";
}
