#include <bits/stdc++.h>
using namespace std;
const int bufSize = 1e6;
inline char nc() {
  static char buf[bufSize], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <typename T>
inline T read(T &r) {
  static char c;
  r = 0;
  for (c = nc(); !isdigit(c);) c = nc();
  for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
  return r;
}
const int maxn = 110;
int n, m;
int dp[maxn][maxn], f[maxn];
vector<pair<int, int> > V[maxn];
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) {
    int k;
    read(k);
    while (k--) {
      int l, r;
      read(l), read(r);
      V[i].push_back(make_pair(l, r));
    }
  }
  for (int len = 1; len <= m; ++len)
    for (int i = 1, j = i + len - 1; j <= m; ++i, ++j) {
      for (int p = 1; p <= m; ++p) f[p] = 0;
      for (int p = 1; p <= n; ++p) {
        for (vector<pair<int, int> >::iterator it = V[p].begin();
             it != V[p].end(); ++it) {
          if (it->first >= i && it->second <= j)
            for (int t = it->first; t <= it->second; ++t) f[t]++;
        }
      }
      for (int k = i; k <= j; ++k)
        dp[i][j] = max(dp[i][j], dp[i][k - 1] + dp[k + 1][j] + f[k] * f[k]);
    }
  printf("%d\n", dp[1][m]);
  return 0;
}
