#include <bits/stdc++.h>
using namespace std;
const int kMAxn = 1e2 + 5;
int N, M;
int L[kMAxn][kMAxn], R[kMAxn][kMAxn];
int dp[kMAxn][kMAxn];
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    int cnt;
    cin >> cnt;
    while (cnt--) {
      int l, r;
      cin >> l >> r;
      for (int j = l; j <= r; j++) {
        L[i][j] = l;
        R[i][j] = r;
      }
    }
  }
  for (int len = 1; len <= M; len++) {
    for (int i = 1; i + len - 1 <= M; i++) {
      int j = i + len - 1;
      for (int k = i; k <= j; k++) {
        int cnt = 0;
        for (int row = 1; row <= N; row++)
          if (L[row][k] >= i && R[row][k] <= j) cnt++;
        dp[i][j] = max(dp[i][j], dp[i][k - 1] + cnt * cnt + dp[k + 1][j]);
      }
    }
  }
  cout << dp[1][M] << endl;
  return 0;
}
