#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
int n, m, pre[110][110], suf[110][110], f[110][110];
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    int cnt = read();
    for (int j = 1; j <= cnt; j++) {
      int l = read(), r = read();
      for (int k = l; k <= r; k++) pre[i][k] = l, suf[i][k] = r;
    }
  }
  for (int len = 1; len <= m; len++) {
    for (int l = 1; l <= m - len + 1; l++) {
      int r = l + len - 1;
      for (int k = l; k <= r; k++) {
        int tmp = 0;
        for (int i = 1; i <= n; i++)
          if (pre[i][k] >= l && suf[i][k] <= r) tmp++;
        f[l][r] = max(f[l][r], f[l][k - 1] + tmp * tmp + f[k + 1][r]);
      }
    }
  }
  printf("%d\n", f[1][m]);
  return 0;
}
