#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
int n, m;
int dp[111][111];
vector<pair<int, int> > intervals[111];
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int k;
    cin >> k;
    while (k--) {
      int start, end;
      cin >> start >> end;
      for (int x = start; x <= end; ++x)
        intervals[x].push_back(make_pair(start, end));
    }
  }
  for (int len = 1; len <= m; ++len) {
    for (int l = 1; l + len - 1 <= m; ++l) {
      int r = l + len - 1;
      for (int k = l; k <= r; ++k) {
        int cnt = 0;
        for (auto& it : intervals[k]) {
          int start = it.first, end = it.second;
          cnt += l <= start && end <= r;
        }
        dp[l][r] = max(dp[l][r], dp[l][k - 1] + dp[k + 1][r] + cnt * cnt);
      }
    }
  }
  cout << dp[1][m] << "\n";
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
