#include <bits/stdc++.h>
using namespace std;
const int N = 105;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
template <typename T>
inline void cmax(T &x, T y) {
  if (x < y) x = y;
}
int n, m, lb[N][N], rb[N][N], dp[N][N];
void init() {
  read(n);
  read(m);
  for (int i = 1; i <= n; ++i) {
    int k;
    read(k);
    while (k--) {
      int l, r;
      read(l);
      read(r);
      for (int j = l; j <= r; ++j) {
        lb[i][j] = l;
        rb[i][j] = r;
      }
    }
  }
}
void solve() {
  for (int l = 1; l <= m; ++l) {
    for (int i = 1, j = i + l - 1; j <= m; ++i, ++j) {
      for (int k = i; k <= j; ++k) {
        int cnt = 0;
        for (int p = 1; p <= n; ++p) {
          cnt += (i <= lb[p][k] && rb[p][k] <= j);
        }
        cmax(dp[i][j], dp[i][k - 1] + cnt * cnt + dp[k + 1][j]);
      }
    }
  }
  printf("%d\n", dp[1][m]);
}
int main() {
  init();
  solve();
  return 0;
}
