#include <bits/stdc++.h>
using namespace std;
int dp[100][100];
pair<int, int> vals[100][100];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  if (fopen("input.in", "r")) {
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
  }
  int n, m;
  cin >> n >> m;
  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--;
      for (int c = a; c <= b; c++) {
        vals[i][c] = {a, b};
      }
    }
  }
  for (int sz = 0; sz < m; sz++) {
    for (int l = 0; l + sz < m; l++) {
      int r = l + sz;
      for (int big = l; big <= r; big++) {
        int segs = 0;
        for (int j = 0; j < n; j++)
          if (vals[j][big].first >= l && vals[j][big].second <= r) segs++;
        int cur = segs * segs;
        if (big - l) cur += dp[l][big - 1];
        if (r - big) cur += dp[big + 1][r];
        dp[l][r] = max(dp[l][r], cur);
      }
    }
  }
  cout << dp[0][m - 1] << "\n";
}
