#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int n, m, dp[N][N], le[N][N], ri[N][N];
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int j = 1; j <= n; j++) {
      int t;
      scanf("%d", &t);
      while (t--) {
        int l, r;
        scanf("%d%d", &l, &r);
        for (int i = l; i <= r; i++) {
          le[j][i] = l;
          ri[j][i] = r;
        }
      }
    }
    for (int l = m; l >= 1; l--) {
      for (int r = l; r <= m; r++) {
        for (int k = l; k <= r; k++) {
          int temp = 0;
          for (int t = 1; t <= n; t++) {
            if (le[t][k] >= l && ri[t][k] <= r) temp++;
          }
          dp[l][r] = max(dp[l][r], dp[l][k - 1] + dp[k + 1][r] + temp * temp);
        }
      }
    }
    cout << dp[1][m] << endl;
  }
  return 0;
}
