#include <bits/stdc++.h>
const int N = 101;
int n, m, dp[N][N], L[N][N], R[N][N];
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1, k, l, r; i <= n; i++) {
    scanf("%d", &k);
    for (int e = 1; e <= k; e++) {
      scanf("%d%d", &l, &r);
      for (int v = l; v <= r; v++) {
        L[i][v] = l;
        R[i][v] = r;
      }
    }
  }
}
int getV(int x, int l, int r) {
  int res = 0;
  for (int i = 1; i <= n; i++)
    if (L[i][x] >= l && R[i][x] <= r) ++res;
  return res;
}
void solve() {
  for (int i = 1; i <= m; i++)
    for (int v = 1; v + i - 1 <= m; v++)
      for (int e = v; e <= v + i - 1; e++) {
        int t = getV(e, v, v + i - 1);
        t = t * t;
        if (e == v && e == v + i - 1)
          dp[v][v + i - 1] = t;
        else if (e == v)
          dp[v][v + i - 1] =
              std::max(dp[v][v + i - 1], dp[v + 1][v + i - 1] + t);
        else if (e == v + i - 1)
          dp[v][v + i - 1] = std::max(dp[v][v + i - 1], dp[v][v + i - 2] + t);
        else
          dp[v][v + i - 1] = std::max(dp[v][v + i - 1],
                                      dp[v][e - 1] + t + dp[e + 1][v + i - 1]);
      }
  printf("%d\n", dp[1][m]);
}
int main() {
  init();
  solve();
  return 0;
}
