#include <bits/stdc++.h>
using namespace std;
const int N = 111;
int dp[N][N];
int n;
struct AC {
  int l, r;
};
vector<AC> v[N];
int find(int k, int l, int r) {
  int sum = 0;
  for (int i = 0; i < (int)v[k].size(); i++)
    if (l <= v[k][i].l && v[k][i].r <= r) sum++;
  return sum * sum;
}
int main() {
  int n, m, s, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s);
    for (int j = 1; j <= s; j++) {
      scanf("%d%d", &x, &y);
      for (int k = x; k <= y; k++) v[k].push_back((AC){x, y});
    }
  }
  for (int len = 1; len <= m; len++) {
    for (int i = 1; i <= m - len + 1; i++) {
      int j = i + len - 1;
      for (int k = i; k <= j; k++)
        dp[i][j] = max(dp[i][j], dp[i][k - 1] + dp[k + 1][j] + find(k, i, j));
    }
  }
  printf("%d\n", dp[1][m]);
  return 0;
}
