#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
const int N = 110;
int Sqr(int x) { return x * x; }
int sum[N][N][N];
int n, m;
int vis[N][N], f[N][N];
int dp(int l, int r) {
  if (l + 1 >= r) return 0;
  if (vis[l][r]) return f[l][r];
  vis[l][r] = 1;
  int res = 0;
  for (int k = l + 1; k < r; ++k) {
    res = max(res, Sqr(sum[k][l][r]) + dp(l, k) + dp(k, r));
  }
  return f[l][r] = res;
}
int main() {
  rd(n), rd(m);
  for (int i = 1; i <= n; ++i) {
    int t, l, r;
    rd(t);
    while (t--) {
      rd(l), rd(r);
      for (int j = l; j <= r; ++j) sum[j][l - 1][r + 1]++;
    }
  }
  for (int i = 1; i <= m; ++i) {
    for (int j = i - 1; j >= 0; --j)
      for (int k = i + 1; k <= m + 1; ++k)
        sum[i][j][k] +=
            sum[i][j + 1][k] + sum[i][j][k - 1] - sum[i][j + 1][k - 1];
  }
  printf("%d", dp(0, m + 1));
  return 0;
}
