#include <bits/stdc++.h>
using namespace std;
const long long maxn = 110;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
long long n, m, dp[maxn][maxn], po[maxn];
vector<pair<long long, long long> > vv[maxn];
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    long long k;
    cin >> k;
    for (long long j = 1; j <= k; j++) {
      long long l, r;
      cin >> l >> r;
      vv[i].push_back({l, r});
    }
  }
  for (long long len = 1; len <= m; len++) {
    for (long long l = 1; l <= m - len + 1; l++) {
      long long r = l + len - 1;
      for (long long i = 1; i <= n; i++) {
        po[i] = upper_bound(vv[i].begin(), vv[i].end(), make_pair(l, INF)) -
                vv[i].begin();
        po[i]--;
        if (po[i] >= vv[i].size()) return 0;
      }
      for (long long k = l; k <= r; k++) {
        long long now = 0;
        for (long long i = 1; i <= n; i++) {
          long long l1 = vv[i][po[i]].first, r1 = vv[i][po[i]].second;
          if (l1 >= l && r1 <= r) now++;
        }
        dp[l][r] = max(dp[l][r], dp[l][k - 1] + dp[k + 1][r] + (now * now));
        for (long long i = 1; i <= n; i++)
          if (vv[i][po[i]].second == k) po[i]++;
      }
    }
  }
  cout << dp[1][m];
  return 0;
}
