#include <bits/stdc++.h>
using namespace std;
const int N = 110, size = 1 << 20, mod = 998244353;
template <class o>
void qr(o &x) {
  char c = getchar();
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o>
void pr1(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  puts("");
}
long long mult(long long a, long long b, long long p) {
  a = (a % p + p) % p;
  b = (b % p + p) % p;
  long long c = (long double)a * b / p;
  return a * b - c * p;
}
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long power(long long a, long long b = mod - 2) {
  long long c = 1;
  while (b) {
    if (b & 1) c = c * a % mod;
    b /= 2;
    a = a * a % mod;
  }
  return c;
}
long long Power(long long a, long long b = mod - 2) {
  long long c = 1;
  while (b) {
    if (b & 1) c = mult(c, a, mod);
    b /= 2;
    a = mult(a, a, mod);
  }
  return c;
}
int n, m, l[N][N], r[N][N], f[N][N];
int w(int L, int R, int x) {
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += (L <= l[i][x] && r[i][x] <= R);
  return ans * ans;
}
int main() {
  qr(n);
  qr(m);
  for (int i = 1, k; i <= n; i++) {
    qr(k);
    for (int j = 1, L, R; j <= k; j++) {
      qr(L);
      qr(R);
      for (int x = L; x <= R; x++) l[i][x] = L, r[i][x] = R;
    }
  }
  for (int k = 1; k <= m; k++) {
    for (int i = 1, j = k; j <= m; i++, j++) {
      for (int x = i; x <= j; x++) {
        f[i][j] = max(f[i][j], f[i][x - 1] + w(i, j, x) + f[x + 1][j]);
      }
    }
  }
  pr2(f[1][m]);
  return 0;
}
