#include <bits/stdc++.h>
using namespace std;
const unsigned seed =
    std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rnd(seed);
const int MOD = 998244353;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> range;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      range.push_back({a, b});
    }
  }
  vector<vector<int>> dp(m + 1, vector<int>(m + 1, 0));
  for (int len = 1; len <= m; len++) {
    for (int s = 0; s + len <= m; s++) {
      vector<pair<int, int>> can;
      vector<int> cnt(m, 0);
      for (auto r : range) {
        if (r.first >= s && r.second < s + len) {
          can.push_back(r);
          for (int i = r.first; i <= r.second; i++) cnt[i]++;
        }
      }
      for (int k = s; k < s + len; k++) {
        dp[s][len] = max(dp[s][len], cnt[k] * cnt[k] + dp[s][k - s] +
                                         dp[k + 1][s + len - k - 1]);
      }
    }
  }
  cout << dp[0][m] << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  int T = 1;
  for (int i = 1; i <= T; i++) {
    solve();
  }
  cout.flush();
  return 0;
}
