#include <bits/stdc++.h>
using namespace std;
const int N = 111;
int n, m, L[N][N], R[N][N], dp[N][N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int k, l, r;
    scanf("%d", &k);
    while (k--) {
      scanf("%d%d", &l, &r);
      for (int d = l; d <= r; ++d) L[i][d] = l, R[i][d] = r;
    }
  }
  for (int len = 1; len <= m; ++len) {
    for (int l = 1, r = len; r <= m; ++l, ++r) {
      for (int k = l; k <= r; ++k) {
        int cnt = 0;
        for (int d = 1; d <= n; ++d)
          if (l <= L[d][k] && R[d][k] <= r) ++cnt;
        dp[l][r] = max(dp[l][r], dp[l][k - 1] + cnt * cnt + dp[k + 1][r]);
      }
    }
  }
  printf("%d\n", dp[1][m]);
}
