#include <bits/stdc++.h>
using namespace std;
long long dp[105][105];
vector<pair<int, int> > intervals;
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    int k;
    cin >> k;
    for (int j = 1; j < k + 1; j++) {
      int l, r;
      cin >> l >> r;
      intervals.push_back({l, r});
    }
  }
  int len = 1;
  while (len <= m) {
    for (int i = 1; i < m + 1; i++) {
      int j = i + len - 1;
      if (j > m) break;
      for (int k = i; k < j + 1; k++) {
        int cnt = 0;
        for (auto x : intervals) {
          if (x.first >= i && x.second <= j && x.first <= k && x.second >= k)
            cnt++;
        }
        dp[i][j] = max(dp[i][j], dp[i][k - 1] + dp[k + 1][j] + 1LL * cnt * cnt);
      }
    }
    len++;
  }
  cout << dp[1][m] << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) solve();
}
