#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) {
    if (vi != v.begin()) os << ", ";
    os << *vi;
  }
  os << "}";
  return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long T, N, M, K;
int dp[110][110], lft[110][110], rgh[110][110];
int solve(int i, int j) {
  if (i > j) return 0;
  if (~dp[i][j]) return dp[i][j];
  int ans = 0;
  for (int k = i; k <= j; k++) {
    int aux = 0;
    for (int l = 0; l < N; l++)
      if (lft[l][k] >= i && rgh[l][k] <= j) aux++;
    ans = max(ans, solve(i, k - 1) + aux * aux + solve(k + 1, j));
  }
  return dp[i][j] = ans;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  int ans = solve(0, M - 1);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int b, c;
      cin >> b >> c;
      b--, c--;
      for (int k = b; k <= c; k++) {
        lft[i][k] = b;
        rgh[i][k] = c;
      }
    }
  }
  solve();
  return 0;
}
