#include <bits/stdc++.h>
using namespace std;
const int primero = 1 << 16;
const int tope = 1 << 17;
void propagaact(int pos, int maximo[tope], int extra[tope]) {
  maximo[pos] = max(maximo[2 * pos] + extra[2 * pos],
                    maximo[2 * pos + 1] + extra[2 * pos + 1]);
}
void propaga(int pos, int maximo[tope], int extra[tope]) {
  while (pos > 1) {
    pos /= 2;
    propagaact(pos, maximo, extra);
  }
}
void inserta(int pos, int val, int maximo[tope], int extra[tope]) {
  pos += primero;
  maximo[pos] = val;
  propaga(pos, maximo, extra);
}
void ponextra(int pos0, int pos1, int val, int maximo[tope], int extra[tope]) {
  pos0 += primero;
  pos1 += primero;
  if (pos0 == pos1) {
    extra[pos0] += val;
  } else {
    extra[pos0] += val;
    extra[pos1] += val;
    while (pos0 / 2 != pos1 / 2) {
      if (pos0 % 2 == 0) extra[pos0 + 1] += val;
      pos0 /= 2;
      propagaact(pos0, maximo, extra);
      if (pos1 % 2 == 1) extra[pos1 - 1] += val;
      pos1 /= 2;
      propagaact(pos1, maximo, extra);
    }
  }
  propaga(pos0, maximo, extra);
}
int n, k;
int ultimo[tope];
int sol[51][tope];
int maximo[51][tope];
int extra[51][tope];
int posant[tope];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    sol[1][i] = sol[1][i - 1] + (ultimo[x] == 0);
    posant[i] = ultimo[x];
    ultimo[x] = i;
  }
  for (int kk = 2; kk <= k; kk++) {
    int(&sant)[tope] = sol[kk - 1];
    int(&m)[tope] = maximo[kk];
    int(&e)[tope] = extra[kk];
    int(&s)[tope] = sol[kk];
    for (int i = 1; i <= n; i++) {
      inserta(i, sant[i - 1], m, e);
      ponextra(posant[i] + 1, i, 1, m, e);
      s[i] = m[1];
    }
  }
  cout << sol[k][n] << endl;
}
