#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long add(long long a, long long b) {
  (a += b) %= M;
  (a += M) %= M;
  return a;
}
long long mul(long long a, long long b) {
  (a *= b) %= M;
  (a += M) %= M;
  return a;
}
long long fastpo(long long a, long long x) {
  if (x == 0) return 1ll;
  if (x == 1) return a;
  long long y = fastpo(a, x / 2);
  if (x % 2 == 0) {
    return y * y;
  }
  return y * y * a;
}
long long inv(long long a, long long M) { return fastpo(a, M - 2); }
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modInverse(long long a, long long m) {
  long long x, y;
  long long g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    return -1;
  else {
    long long res = (x % m + m) % m;
    return res;
  }
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void print(vector<int> &a) {
  int n = a.size();
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> l(n + 2, vector<int>(m + 2, 0)),
      r(n + 2, vector<int>(m + 2, 0));
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a, b;
      cin >> a >> b;
      for (int p = a; p <= b; p++) {
        l[i][p] = a;
        r[i][p] = b;
      }
    }
  }
  vector<vector<int>> dp(m + 2, vector<int>(m + 2, 0));
  for (int d = 1; d <= m; d++) {
    for (int i = 1; i + d - 1 <= m; i++) {
      int j = i + d - 1;
      for (int k = i; k <= j; k++) {
        int ans = 0;
        for (int p = 1; p <= n; p++) {
          int li = l[p][k], ri = r[p][k];
          if (li >= i && ri <= j) ans++;
        }
        ans *= ans;
        dp[i][j] = max(dp[i][j], dp[i][k - 1] + ans + dp[k + 1][j]);
      }
    }
  }
  int sol = dp[1][m];
  cout << sol << endl;
  return 0;
}
