#include <bits/stdc++.h>
using namespace std;
template <class t>
vector<t> sort(vector<t> &a) {
  return sort(a.begin(), a.end());
}
int dp[101][101];
int n, m;
pair<int, int> c[101][101];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int l, r;
      cin >> l >> r;
      for (int a = l; a <= r; a++) c[i][a] = {l, r};
    }
  }
  for (int d = 0; d < m; d++)
    for (int l = 1; l + d <= m; l++) {
      int r = l + d;
      if (l == r) {
        int numint = 0;
        for (int a = 1; a <= n; a++)
          if (l <= c[a][l].first && c[a][r].second <= r) numint++;
        dp[l][r] = numint * numint;
      } else {
        for (int k = l; k <= r; k++) {
          int numint = 0;
          for (int a = 1; a <= n; a++)
            if (l <= c[a][k].first && c[a][k].second <= r) numint++;
          dp[l][r] =
              max(dp[l][r], dp[l][k - 1] + numint * numint + dp[k + 1][r]);
        }
      }
    }
  cout << dp[1][m] << '\n';
  return 0;
}
