#include <bits/stdc++.h>
using namespace std;
int a[100 + 7][100 + 7], dp[100 + 7][100 + 7];
int main() {
  vector<pair<long long, long long> > v;
  long long N, i, j, n, m, k, L, R, notr = 0, s, p;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    for (j = 1; j <= k; j++) {
      cin >> L >> R;
      v.push_back({L, R});
      for (p = L; p <= R; p++) a[i][p] = notr;
      notr++;
    }
  }
  for (j = 1; j <= m; j++) {
    for (i = 1; i <= m; i++) {
      if (i + j - 1 > m) break;
      for (k = i; k <= i + j - 1; k++) {
        s = 0;
        for (p = 1; p <= n; p++) {
          notr = a[p][k];
          if (v[notr].first >= i && v[notr].second <= i + j - 1) s++;
        }
        if (s * s + dp[i][k - 1] + dp[k + 1][i + j - 1] > dp[i][i + j - 1])
          dp[i][i + j - 1] = s * s + dp[i][k - 1] + dp[k + 1][i + j - 1];
      }
    }
  }
  cout << dp[1][m];
}
