#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m;
int a[N][N], L[N * N], R[N * N];
long long dp[N][N];
long long solve(int l, int r) {
  if (l > r) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  long long ans = 0;
  for (int mid = l; mid <= r; mid++) {
    int cst = 0;
    for (int i = 1; i <= n; i++) {
      if (L[a[i][mid]] < l or R[a[i][mid]] > r) continue;
      cst++;
    }
    ans = max(ans, 1ll * cst * cst + solve(l, mid - 1) + solve(mid + 1, r));
  }
  return dp[l][r] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int id = 0;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    while (k--) {
      ++id;
      int l, r;
      cin >> l >> r;
      for (int j = l; j <= r; j++) {
        a[i][j] = id;
      }
      L[id] = l, R[id] = r;
    }
  }
  memset(dp, -1, sizeof dp);
  long long ans = solve(1, m);
  cout << ans << endl;
  return 0;
}
