#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> mas(n, vector<long long>(m, 0)),
      left(n, vector<long long>(m, -1)), right(n, vector<long long>(m, -1));
  for (long long k = 0; k < n; k++) {
    long long kol;
    cin >> kol;
    for (long long i = 0; i < kol; i++) {
      long long l, r;
      cin >> l >> r;
      l--;
      r--;
      for (long long j = l; j <= r; j++) {
        left[k][j] = l;
        right[k][j] = r;
      }
    }
  }
  vector<vector<long long>> dp(m + 1, vector<long long>(m + 1, 0));
  for (long long len = 1; len <= m; len++) {
    for (long long l = 0; len + l <= m; l++) {
      for (long long k = l; k < len + l; k++) {
        long long num = 0;
        for (long long i = 0; i < n; i++) {
          if (left[i][k] >= l && right[i][k] <= l + len - 1) {
            num++;
          }
        }
        dp[l][l + len - 1] =
            max(dp[l][l + len - 1], ((k - 1 >= 0) ? dp[l][k - 1] : 0) +
                                        num * num + dp[k + 1][l + len - 1]);
      }
    }
  }
  cout << dp[0][m - 1] << endl;
}
