#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int L[N][M], R[N][M];
  for (int i = 0; i < (N); i++) {
    int K;
    cin >> K;
    for (int j = 0; j < (K); j++) {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      for (int k = l; k < (r + 1); k++) {
        L[i][k] = l;
        R[i][k] = r;
      }
    }
  }
  int dp[M][M];
  for (int i = 0; i < (M); i++) {
    int cnt = 0;
    for (int j = 0; j < (N); j++) {
      if (L[j][i] == R[j][i]) cnt++;
    }
    dp[i][i] = cnt * cnt;
  }
  for (int d = 0; d < (M); d++) {
    for (int i = 0; i < (M); i++) {
      int j = i + d;
      if (j >= M) continue;
      dp[i][j] = 0;
      for (int k = i; k < (j + 1); k++) {
        int cur = 0;
        for (int l = 0; l < (N); l++) {
          if (L[l][k] >= i && R[l][k] <= j) cur++;
        }
        cur *= cur;
        if (i != k) cur += dp[i][k - 1];
        if (j != k) cur += dp[k + 1][j];
        ckmax(dp[i][j], cur);
      }
    }
  }
  cout << dp[0][M - 1] << nl;
  return 0;
}
