#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
long long fac[1] = {1}, inv[1] = {1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mp(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}
long long cmb(long long r, long long c) {
  return fac[r] * inv[c] % MOD * inv[r - c] % MOD;
}
priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;
int le[100][100], ri[100][100];
int dp[100][100];
int n, m;
int go(int l, int r) {
  if (l > r) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  int mav = 0;
  for (int i = l; i <= r; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) cnt += le[j][i] >= l && ri[j][i] <= r;
    mav = max(mav, cnt * cnt + go(l, i - 1) + go(i + 1, r));
  }
  return dp[l][r] = mav;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int a, b;
      scanf("%d %d", &a, &b);
      a--;
      b--;
      for (int j = a; j <= b; j++) {
        le[i][j] = a;
        ri[i][j] = b;
      }
    }
  }
  printf("%d", go(0, m - 1));
}
