#include <bits/stdc++.h>
using namespace std;
int read() {
  int k = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
  return k * f;
}
const int N = 205;
int n, m, l[N][N], r[N][N], dp[N][N];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y, z;
    for (int j = 1; j <= x; j++) {
      y = read();
      z = read();
      for (int k = y; k <= z; k++) l[i][k] = y, r[i][k] = z;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m - i + 1; j++) {
      int R = j + i - 1;
      for (int k = j; k <= R; k++) {
        int sum = 0;
        for (int w = 1; w <= n; w++) {
          if (l[w][k] >= j && r[w][k] <= R) sum++;
        }
        dp[j][R] = max(dp[j][R], dp[j][k - 1] + sum * sum + dp[k + 1][R]);
      }
    }
  }
  cout << dp[1][m] << endl;
  return 0;
}
