#include <bits/stdc++.h>
const int MAX = 110;
using namespace std;
int n, m;
int qtd[MAX];
long long dp[MAX][MAX];
vector<int> vec[MAX];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1, k; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 0, l, r; j < k; j++) {
      scanf("%d%d", &l, &r);
      vec[i].push_back(r);
    }
  }
  for (int diff = 0; diff < m; diff++)
    for (int l = 1; l + diff <= m; l++) {
      int r = l + diff;
      for (int i = 1; i <= m; i++) qtd[i] = 0;
      for (int i = 1; i <= n; i++) {
        int last = 0;
        for (int j = 0; j < (int)(vec[i].size()); j++) {
          int esq = last + 1, dir = vec[i][j];
          if (esq >= l && dir <= r) {
            for (int g = esq; g <= dir; g++) qtd[g]++;
          }
          last = dir;
        }
      }
      for (int i = l; i <= r; i++)
        dp[l][r] = max(dp[l][r], dp[l][i - 1] + dp[i + 1][r] +
                                     (long long)(qtd[i]) * (long long)(qtd[i]));
    }
  printf("%lld\n", dp[1][m]);
}
