#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<set<int>> S(n);
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    S[i].insert(0);
    for (int q = 0; q < k; ++q) {
      int a, b;
      cin >> a >> b;
      S[i].insert(b);
    }
  }
  vector<vector<int>> ans(m + 2, vector<int>(m + 2));
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= m - i + 1; ++j) {
      int l = j;
      int r = j + i - 1;
      for (int k = l; k <= r; ++k) {
        int col = 0;
        for (int q = 0; q < n; ++q) {
          auto it1 = --S[q].lower_bound(k);
          auto it2 = it1;
          ++it2;
          int ll = *it1 + 1;
          int rr = *it2;
          if (ll >= l && rr <= r && k >= ll && k <= rr) {
            ++col;
          }
        }
        ans[l][r] = max(ans[l][r], ans[l][k - 1] + ans[k + 1][r] + col * col);
      }
    }
  }
  cout << ans[1][m];
  return 0;
}
