#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long N = 105;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const int INFi = 0x7f7f7f7f;
long long test = 1, n, m, a[N][N], ct[N], cnt = 1, dp[N][N];
set<pair<long long, long long> > adj[N];
long long del(int x, int c) {
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    auto it = adj[i].upper_bound({c, INF});
    it--;
    int first = 0;
    if (a[i][(*it).first] == 0) a[i][(*it).first] = x, first = 1;
    cnt += first;
  }
  return cnt * cnt;
}
void add(int x, int c) {
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    auto it = adj[i].upper_bound({c, INF});
    it--;
    int first = 0;
    if (a[i][(*it).first] == x) a[i][(*it).first] = 0, first = 1;
    cnt += first;
  }
}
long long mem(int l, int r) {
  if (l > r) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  long long ans = 0;
  for (int i = l; i <= r; i++) {
    long long tmp = cnt++;
    long long x = del(tmp, i);
    ans = max(ans, mem(l, i - 1) + mem(i + 1, r) + x);
    add(tmp, i);
  }
  return dp[l][r] = ans;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int x, l, r;
    cin >> x;
    for (int j = 1; j <= x; j++) {
      cin >> l >> r;
      adj[i].insert({l, r});
    }
  }
  cout << mem(1, m) << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  for (int i = 1; i <= test; i++) {
    solve();
  }
}
