#include <bits/stdc++.h>
using namespace std;
const long long N = 110;
long long n, m, k, l, r, s[N][N], t[N][N], f[N][N];
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &k);
    for (long long j = 1; j <= k; j++) {
      scanf("%lld%lld", &l, &r);
      for (long long k = l; k <= r; k++) s[i][k] = l, t[i][k] = r;
    }
  }
  for (long long i = 1; i <= m; i++) {
    long long cnt = 0;
    for (long long k = 1; k <= n; k++) cnt += (s[k][i] == t[k][i]);
    f[i][i] = cnt * cnt;
  }
  for (long long len = 2; len <= m; len++)
    for (long long i = 1; i <= m - len + 1; i++) {
      long long l = i, r = i + len - 1;
      for (long long k = l; k <= r; k++) {
        long long cnt = 0;
        for (long long p = 1; p <= n; p++)
          cnt += (s[p][k] >= l && t[p][k] <= r);
        f[l][r] = max(f[l][r], (k == l ? 0 : f[l][k - 1]) +
                                   (k == r ? 0 : f[k + 1][r]) + cnt * cnt);
      }
    }
  printf("%lld\n", f[1][m]);
  return 0;
}
