#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 200;
const int inf = 0x3f3f3f3f;
const int INF = 0x7f7f7f7f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int n, m;
int l, r;
int n1;
int dp1[maxn][maxn], dp2[maxn][maxn];
int dp[maxn][maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    cin >> n1;
    for (int j = 1; j < n1 + 1; j++) {
      cin >> l >> r;
      for (int z = l; z < r + 1; z++) {
        dp1[i][z] = l;
        dp2[i][z] = r;
      }
    }
  }
  for (int i = m + 1 - 1; i >= 1; i--) {
    for (int j = 1; j < m + 1; j++) {
      for (int z = 1; z < j + 1; z++) {
        int sum = 0;
        for (int k = 1; k < n + 1; k++) {
          if (dp2[k][z] <= j && dp1[k][z] >= i) {
            sum++;
          }
        }
        dp[i][j] = max(dp[i][j], dp[i][z - 1] + dp[z + 1][j] + sum * sum);
      }
    }
  }
  cout << dp[1][m] << "\n";
  return 0;
}
