#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};
int add(int a, int b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
int mult(int a, int b) { return ((ll)a * b) % MOD; }
void setIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
const int mxN = 101;
int amt[mxN][mxN][mxN];
int dp[mxN][mxN];
int main() {
  setIO();
  int n, m;
  cin >> 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 a = l; a >= 0; --a) {
        for (int b = r; b < m; ++b) {
          for (int c = l; c <= r; ++c) {
            ++amt[a][b][c];
          }
        }
      }
    }
  }
  for (int sz = 0; sz < m; ++sz) {
    for (int i = 0; i + sz < m; ++i) {
      int l = i, r = i + sz;
      for (int k = l; k <= r; ++k) {
        int cur = 0;
        if (k > l) cur += dp[l][k - 1];
        if (k < r) cur += dp[k + 1][r];
        cur += amt[l][r][k] * amt[l][r][k];
        dp[l][r] = max(dp[l][r], cur);
      }
    }
  }
  cout << dp[0][m - 1] << "\n";
}
