#include <bits/stdc++.h>
using namespace std;
long long sqr(long long a) { return a * a; }
long long ints[110][110], dp[110][110];
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    for (long long j = 0; j < k; j++) {
      long long l, r;
      cin >> l >> r;
      ints[l][r] += 1;
    }
  }
  for (long long i = 2; i < m + 1; i++)
    for (long long j = i - 1; j >= 1; j--)
      ints[j][i] += ints[j + 1][i] + ints[j][i - 1] - ints[j + 1][i - 1];
  for (long long i = 1; i < m + 1; i++)
    for (long long j = i + 1 - 1; j >= 1; j--)
      for (long long k = j; k < i + 1; k++) {
        dp[j][i] = max(dp[j][i],
                       dp[j][k - 1] +
                           sqr(ints[j][i] - ints[j][k - 1] - ints[k + 1][i]) +
                           dp[k + 1][i]);
      }
  cout << dp[1][m] << endl;
}
