#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const char nl = '\n';
const int N = 100 + 5;
int n, m, k;
int l_bound[N][N], r_bound[N][N], dp[N][N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    for (int kk = 0; kk < k; kk++) {
      int l, r;
      cin >> l >> r;
      for (int j = l; j <= r; j++) {
        l_bound[i][j] = l;
        r_bound[i][j] = r;
      }
    }
  }
  for (int len = 1; len <= m; len++) {
    for (int l = 1, r = len; r <= m; l++, r++) {
      for (k = l; k <= r; k++) {
        int temp = 0;
        for (int i = 1; i <= n; i++) {
          if (l_bound[i][k] >= l && r_bound[i][k] <= r) temp++;
        }
        dp[l][r] = max(dp[l][r], dp[l][k - 1] + temp * temp + dp[k + 1][r]);
      }
    }
  }
  cout << dp[1][m] << nl;
  return 0;
}
