#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 1067, T = 67;
int f[N][T], it[T][N], lz[T][N], trai[N], phai[N], a[N];
void build(int x, int l, int r) {
  trai[x] = l;
  phai[x] = r;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
}
void down(int t, int x) {
  lz[t][x * 2] += lz[t][x];
  it[t][x * 2] += lz[t][x];
  lz[t][x * 2 + 1] += lz[t][x];
  it[t][x * 2 + 1] += lz[t][x];
  lz[t][x] = 0;
}
void update(int t, int x, int l, int r, int c) {
  if (l > phai[x] || r < trai[x]) return;
  if (trai[x] >= l && phai[x] <= r) {
    it[t][x] += c;
    lz[t][x] += c;
    return;
  }
  down(t, x);
  update(t, x * 2, l, r, c);
  update(t, x * 2 + 1, l, r, c);
  it[t][x] = max(it[t][x * 2], it[t][x * 2 + 1]);
}
int last[N];
map<long long, long long> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  ;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  build(1, 0, n);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= k - 1; j++) update(j, 1, last[a[i]], i - 1, 1);
    last[a[i]] = i;
    for (long long j = 1; j <= k; j++) {
      f[i][j] = it[j - 1][1];
      update(j, 1, i, i, f[i][j]);
    }
  }
  cout << f[n][k] << endl;
  return 0;
}
