#include <bits/stdc++.h>
using namespace std;
template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& input) {
  for (auto const& i : input) {
    os << i << " ";
  }
  return os;
}
template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& input) {
  for (auto const& i : input) {
    os << i << " ";
  }
  return os;
}
template <class T, size_t n>
std::ostream& operator<<(std::ostream& os, const std::array<T, n>& input) {
  for (size_t i = 0; i < n; ++i) {
    os << input[i] << " ";
  }
  return os;
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& input) {
  os << "(" << input.first << ", " << input.second << ')';
  return os;
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os,
                         const std::unordered_map<T1, T2>& input) {
  for (auto const& i : input) {
    os << i << " ";
  }
  return os;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
double startTime;
double getCurrentTime() {
  return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int maxn = 101;
int L[maxn][maxn], R[maxn][maxn];
int dp[maxn][maxn];
bool vis[maxn][maxn];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < int(n); ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < int(k); ++j) {
      int l, r;
      cin >> l >> r;
      l--;
      for (int t = l; t < int(r); ++t) L[i][t] = l, R[i][t] = r;
    }
  }
  function<int(int, int)> get = [&](int l, int r) {
    if (l >= r) return 0;
    if (vis[l][r]) return dp[l][r];
    vis[l][r] = 1;
    for (int k = l; k < int(r); ++k) {
      int cnt = 0;
      for (int i = 0; i < int(n); ++i)
        if (L[i][k] >= l && R[i][k] <= r) cnt++;
      dp[l][r] = max(cnt * cnt + get(l, k) + get(k + 1, r), dp[l][r]);
    }
    return dp[l][r];
  };
  cout << get(0, m) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int cas = 1;
  for (int ca = 0; ca < int(cas); ++ca) solve();
  return 0;
}
