#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long mod = 998244353;
int l[101][101], r[101][101], dp[101][101];
void solve() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int Q;
    scanf("%d", &Q);
    while (Q--) {
      int L, R;
      scanf("%d %d", &L, &R);
      for (int j = L; j <= R; j++) l[i][j] = L, r[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 c = 0;
        for (int i = 1; i <= n; i++) {
          if (L <= l[i][k] && r[i][k] <= R) {
            c++;
          }
        }
        dp[L][R] = max(dp[L][R], dp[L][k - 1] + dp[k + 1][R] + c * c);
      }
    }
  }
  printf("%d\n", dp[1][m]);
}
int main() {
  solve();
  return 0;
}
