#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
const long long INF = 1e18;
const double E = 1e-18;
const double PI = acos(-1);
mt19937_64 rnd(time(0));
long long p1 = 31, p2 = 37, p3 = 7, p4 = rnd() % 100 + 1, md1 = MOD,
          md2 = 998244353, md3 = 998244357, md4 = rnd() % 1000000000;
long long n, m, T, dp[105][105];
pair<long long, long long> a[105][105];
long long binpow(long long h, long long r, long long md = MOD) {
  long long l = 1;
  while (r) {
    if (r & 1) l *= h, l %= md;
    h *= h;
    h %= md;
    r /= 2;
  }
  return l;
}
long long gcd(long long x, long long y) {
  if (x < y) swap(x, y);
  while (x && y) {
    x %= y;
    swap(x, y);
  }
  return x + y;
}
void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      long long x, y;
      cin >> x >> y;
      for (int u = x; u <= y; u++) a[i][u] = make_pair(x, y);
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= m - j + 1; i++) {
      for (int u = i; u <= i + j - 1; u++) {
        long long o = 0;
        for (int k = 1; k <= n; k++)
          o += (a[k][u].first >= i && a[k][u].second <= i + j - 1);
        dp[i][i + j - 1] =
            max(dp[i][i + j - 1], dp[i][u - 1] + dp[u + 1][i + j - 1] + o * o);
      }
    }
  }
  cout << dp[1][m] << "\n";
  return 0;
}
