#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int S[N][N][N] = {};
int dp[N][N] = {};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int g, l, r;
    cin >> g;
    while (g--) {
      cin >> l >> r;
      for (int a = l; a > 0; a--)
        for (int b = r; b <= m; b++) S[a][b][l]++, S[a][b][r + 1]--;
    }
  }
  for (int l = 1; l <= m; l++)
    for (int r = l; r <= m; r++)
      for (int k = l + 1; k <= r; k++) S[l][r][k] += S[l][r][k - 1];
  for (int len = 1; len <= m; len++)
    for (int l = 1, r = len; r <= m; l++, r++)
      for (int k = l; k <= r; k++)
        dp[l][r] = max(dp[l][r],
                       dp[l][k - 1] + S[l][r][k] * S[l][r][k] + dp[k + 1][r]);
  cout << dp[1][m] << '\n';
  return 0;
}
