#include <bits/stdc++.h>
using namespace std;
int n, m;
int lef[105][105], rig[105][105];
int dp[105][105];
void crystal() {
  int val;
  for (int st = m; st >= 1; --st)
    for (int ed = st; ed <= m; ++ed)
      for (int k = st; k <= ed; ++k) {
        val = 0;
        for (int i = 1; i <= n; ++i)
          if (lef[i][k] >= st && rig[i][k] <= ed) ++val;
        dp[st][ed] = max(dp[st][ed], dp[st][k - 1] + dp[k + 1][ed] + val * val);
      }
  cout << dp[1][m];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int k, u, v;
  for (int i = 1; i <= n; ++i) {
    cin >> k;
    for (int t = 1; t <= k; ++t) {
      cin >> u >> v;
      for (int z = u; z <= v; ++z) lef[i][z] = u, rig[i][z] = v;
    }
  }
  crystal();
}
