#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int l[105][105], r[105][105];
  int now = 1;
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int first, second;
      scanf("%d %d", &first, &second);
      for (int a = first; a <= second; a++) l[i][a] = first, r[i][a] = second;
    }
  }
  int dp[105][105];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < m; i++) {
    for (int j = 1; j + i <= m; j++) {
      for (int k = j; k <= j + i; k++) {
        int cnt = 0;
        for (int first = 1; first <= n; first++) {
          if (l[first][k] >= j && r[first][k] <= j + i) cnt++;
        }
        dp[j][j + i] =
            max(dp[j][j + i], cnt * cnt + dp[j][k - 1] + dp[k + 1][j + i]);
      }
    }
  }
  printf("%d\n", dp[1][m]);
  return 0;
}
