#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> al(n + 100, vector<int>(m + 100)),
      ar(n + 100, vector<int>(m + 100)), d(1000, vector<int>(1000));
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    for (int x = 1; x <= k; x++) {
      int a, b;
      cin >> a >> b;
      for (int j = a; j <= b; j++) {
        al[i][j] = a;
        ar[i][j] = b;
      }
    }
  }
  for (int l = m; l >= 1; l--) {
    for (int r = l; r <= m; r++) {
      for (int k = l; k <= r; k++) {
        int x = 0;
        for (int i = 1; i <= n; i++) {
          if (al[i][k] >= l && ar[i][k] <= r) x++;
        }
        d[l][r] = max(d[l][r], d[l][k - 1] + d[k + 1][r] + x * x);
      }
    }
  }
  cout << d[1][m] << endl;
}
