#include <bits/stdc++.h>
using namespace std;
long long n, m;
int k[103];
int l[103][103], r[103][103];
int memo[103][103];
int sol(int left, int right) {
  if (memo[left][right] != -1) return memo[left][right];
  memo[left][right] = 0;
  for (int column = left; column <= right; column++) {
    int value = 0;
    for (int row = 0; row < n; row++) {
      if (l[row][column] >= left and r[row][column] <= right) value++;
    }
    memo[left][right] =
        max(memo[left][right],
            sol(left, column - 1) + sol(column + 1, right) + value * value);
  }
  return memo[left][right];
}
int main() {
  for (int i = 0; i < 103; i++)
    for (int j = 0; j < 103; j++) memo[i][j] = -1;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int laux, raux;
      cin >> laux >> raux;
      laux--;
      raux--;
      for (int k = laux; k <= raux; k++) {
        l[i][k] = laux;
        r[i][k] = raux;
      }
    }
  }
  cout << sol(0, m - 1) << endl;
}
