#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, x, l, r, cnt[N][N][N], dp[N][N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    while (x--) {
      scanf("%d%d", &l, &r);
      for (int j = 1; j <= l; j++)
        for (int k = r; k <= m; k++)
          for (int v = l; v <= r; v++) cnt[j][k][v]++;
    }
  }
  for (int i = m; i; i--)
    for (int j = i; j <= m; j++)
      for (int k = i; k <= j; k++)
        dp[i][j] = max(dp[i][j], dp[i][k - 1] + dp[k + 1][j] +
                                     cnt[i][j][k] * cnt[i][j][k]);
  printf("%d\n", dp[1][m]);
}
