#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int dp[maxn][maxn];
int lm[maxn][maxn], rm[maxn][maxn];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int l, r;
      scanf("%d%d", &l, &r);
      for (int j = l; j <= r; j++) {
        lm[i][j] = l;
        rm[i][j] = r;
      }
    }
  }
  for (int l = m; l >= 1; l--) {
    for (int r = l; r <= m; r++) {
      for (int k = l; k <= r; k++) {
        int cnt = 0;
        for (int i = 1; i <= n; i++)
          if (l <= lm[i][k] && rm[i][k] <= r) ++cnt;
        int lv = (k - 1 >= l ? dp[l][k - 1] : 0);
        int rv = (k + 1 <= r ? dp[k + 1][r] : 0);
        dp[l][r] = max(dp[l][r], lv + rv + cnt * cnt);
      }
    }
  }
  printf("%d\n", dp[1][m]);
  return 0;
}
