#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pqd = priority_queue<T>;
template <typename T>
using pqa = priority_queue<T, vector<T>, greater<T>>;
string to_string(string c) { return string(c); }
string to_string(char ch) { return string(1, ch); }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N>
string to_string(bitset<N> B) {
  string second = "";
  for (long long i = 0; i < (long long)N; i++) second += (char)'0' + B[i];
  return second;
}
template <typename T, typename U>
string to_string(pair<T, U> P) {
  return "{" + to_string(P.first) + "," + to_string(P.second) + "}";
}
template <typename T>
string to_string(T A) {
  string second = "[";
  bool first = 0;
  for (auto x : A) {
    if (first) second += " ";
    first = 1;
    second += to_string(x);
  }
  return second + "]";
}
template <typename T, size_t N>
string to_string(T (&A)[N]) {
  string second = "[";
  bool first = 0;
  for (long long i = 0; i < N; i++) {
    if (first) second += " ";
    first = 1;
    second += to_string(A[i]);
  }
  return second + "]";
}
void _deb() { cerr << "\n"; }
template <typename T, typename... U>
void _deb(const T& t, const U&... u) {
  cerr << to_string(t);
  if (sizeof...(u)) cout << ", ";
  _deb(u...);
}
const long long MX = 5e5 + 5;
const long long OO = 1e18;
const long long MOD = 1e9 + 7;
const long long DX[8] = {1, 0, -1, 0, 1, -1, 1, -1};
const long long DY[8] = {0, 1, 0, -1, 1, -1, -1, 1};
long long ceil(long long a, long long b) {
  return a / b + (a % b && (a ^ b) > 0);
}
long long floor(long long a, long long b) {
  return a / b - (a % b && (a ^ b) < 0);
}
long long SBITS(long long n) { return __builtin_popcountll(n); }
long long BITS(long long n) { return 63 - __builtin_clzll(n); }
template <typename T, typename U>
T fstTrue(U f, T L = 0LL, T R = OO) {
  while (L < R) {
    T mid = L + ((R - L) >> 1);
    f(mid) ? R = mid : L = mid + 1;
  }
  return L;
}
template <typename T, typename U>
T lstTrue(U f, T L = 0LL, T R = OO) {
  while (L < R) {
    T mid = L + ((R - L + 1) >> 1);
    f(mid) ? L = mid : R = mid - 1;
  }
  return L;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long range[m + 2][m + 2][m + 2];
  memset(range, 0, sizeof(range));
  for (long long i = 1; i <= n; i++) {
    long long l, r, k;
    cin >> k;
    while (k--) {
      cin >> l >> r;
      for (long long j = l; j <= r; j++) range[j][l][r]++;
    }
  }
  long long dp[m + 2][m + 2];
  memset(dp, 0, sizeof(dp));
  for (long long l = m; l >= 1; l--) {
    for (long long r = 1; r <= m; r++) {
      if (l > r)
        dp[l][r] = 0;
      else {
        for (long long i = l; i <= r; i++) {
          range[i][l][r] +=
              range[i][l + 1][r] + range[i][l][r - 1] - range[i][l + 1][r - 1];
          dp[l][r] = max(dp[l][r], dp[l][i - 1] + dp[i + 1][r] +
                                       range[i][l][r] * range[i][l][r]);
        }
      }
    }
  }
  cout << dp[1][m] << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  cerr << "Time: " << (float)clock() / CLOCKS_PER_SEC << " s";
  return 0;
}
