#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
int n, m;
pair<int, int> mp[100][100];
int dp[100][100];
int solve(int x, int y) {
  if (y < x) {
    return 0;
  }
  if (dp[x][y] != -1) return dp[x][y];
  int ans = 0;
  for (int z = x; z <= y; z++) {
    int k = 0;
    for (int i = 0; i < n; ++i) {
      if (mp[i][z].first >= x and mp[i][z].second <= y) {
        k++;
      }
    }
    ans = max(ans, k * k + solve(x, z - 1) + solve(z + 1, y));
  }
  return dp[x][y] = ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int u, l, r;
    cin >> u;
    for (int j = 0; j < u; ++j) {
      cin >> l >> r;
      --l;
      --r;
      for (int k = l; k < r + 1; ++k) {
        mp[i][k] = {l, r};
      }
    }
  }
  memset(dp, -1, sizeof dp);
  cout << solve(0, m - 1) << endl;
  return 0;
}
