#include <bits/stdc++.h>
using namespace std;
int n, m;
int dp[111][111];
int num;
int l[110][110], r[110][110];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int tmp, ll, rr;
    scanf("%d", &tmp);
    for (int j = 1; j <= tmp; j++) {
      scanf("%d%d", &ll, &rr);
      for (int j = ll; j <= rr; j++) {
        l[i][j] = ll;
        r[i][j] = rr;
      }
    }
  }
  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 x = 1; x <= n; x++)
          if (i <= l[x][k] && r[x][k] <= j) cnt++;
        dp[i][j] = max(dp[i][k - 1] + dp[k + 1][j] + cnt * cnt, dp[i][j]);
      }
    }
  }
  printf("%d\n", dp[1][m]);
}
