#include <bits/stdc++.h>
using namespace std;
const int N = 109;
int n, m;
int lft[N][N], rgt[N][N];
bool seen[N][N];
int sv[N][N];
int solve(int l, int r) {
  if (l > r) return 0;
  if (seen[l][r]) {
    return sv[l][r];
  }
  int ret = 0;
  for (int k = l; k <= r; ++k) {
    int cand = 0;
    cand += solve(l, k - 1);
    cand += solve(k + 1, r);
    int cur = 0;
    for (int i = 0; i < n; ++i) {
      if (lft[i][k] >= l && rgt[i][k] <= r) {
        cur++;
      }
    }
    cand += cur * cur;
    ret = max(ret, cand);
  }
  seen[l][r] = true;
  sv[l][r] = ret;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int l, r;
      cin >> l >> r;
      for (int a = l; a <= r; ++a) {
        lft[i][a] = l;
        rgt[i][a] = r;
      }
    }
  }
  int ans = solve(1, m);
  cout << ans << '\n';
  return 0;
}
