#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vll = vector<ll>;
using vvll = vector<vll>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vpii> k(n + 1);
  vvi rf(n + 1, vi(m + 1));
  for (int i = 1; i <= n; i++) {
    int tk;
    cin >> tk;
    for (int j = 0; j <= tk - 1; j++) {
      int l, r;
      cin >> l >> r;
      for (int e = l; e <= r; e++) rf[i][e] = j;
      k[i].push_back({l, r});
    }
  }
  vvi dp(m + 2, vi(m + 2));
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m - i + 1; j++) {
      int l = j, r = j + i - 1;
      for (int e = l; e <= r; e++) {
        int cnt = 0;
        for (int h = 1; h <= n; h++) {
          if (k[h][rf[h][e]].first >= l && k[h][rf[h][e]].second <= r) cnt++;
        }
        dp[l][r] = max(dp[l][r], dp[l][e - 1] + cnt * cnt + dp[e + 1][r]);
      }
    }
  }
  cout << dp[1][m] << endl;
}
