#include <bits/stdc++.h>
using namespace std;
const long long max_n = 1e2 + 5;
long long n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  vector<vector<long long> > left(n), right(n);
  for (long long i = 0; (1 > 0 and i < n) or (1 < 0 and i > n); i += 1) {
    long long k;
    cin >> k;
    left[i].resize(m + 1);
    right[i].resize(m + 1);
    for (long long j = 0; (1 > 0 and j < k) or (1 < 0 and j > k); j += 1) {
      long long l, r;
      cin >> l >> r;
      for (long long z = l; (1 > 0 and z < r + 1) or (1 < 0 and z > r + 1);
           z += 1) {
        left[i][z] = l;
        right[i][z] = r;
      }
    }
  }
  vector<vector<long long> > dp(m + 2);
  for (long long i = 0; (1 > 0 and i < m + 2) or (1 < 0 and i > m + 2);
       i += 1) {
    dp[i].resize(m + 2);
    for (long long j = 0; (1 > 0 and j < m + 2) or (1 < 0 and j > m + 2);
         j += 1)
      dp[i][j] = 0;
  }
  for (long long i = m; (-1 > 0 and i < 0) or (-1 < 0 and i > 0); i += -1) {
    for (long long j = i; (1 > 0 and j < m + 1) or (1 < 0 and j > m + 1);
         j += 1) {
      for (long long x = i; (1 > 0 and x < j + 1) or (1 < 0 and x > j + 1);
           x += 1) {
        long long cntr = 0;
        for (long long q = 0; (1 > 0 and q < n) or (1 < 0 and q > n); q += 1)
          if (left[q][x] >= i and right[q][x] <= j) ++cntr;
        dp[i][j] = max(dp[i][j], dp[i][x - 1] + (cntr * cntr) + dp[x + 1][j]);
      }
    }
  }
  cout << dp[1][m] << endl;
  return 0;
}
