#include <bits/stdc++.h>
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int N = 35010;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
using namespace std;
template <class T>
inline bool rd(T &num) {
  char in = getchar();
  bool ok = false;
  if (in == EOF) return false;
  while (in != '-' && (in < '0' || in > '9')) in = getchar();
  if (in == '-') {
    ok = true;
    num = 0;
  } else
    num = in - '0';
  while (in = getchar(), in >= '0' && in <= '9') {
    num *= 10, num += in - '0';
  }
  if (ok) num = -num;
  return true;
}
int n, m, a[N], dp[N][55], pos[N], mx[N << 2], tag[N << 2];
vector<int> vt[N];
void Pushup(int rt) { mx[rt] = max(mx[(rt << 1)], mx[(rt << 1 | 1)]); }
void Pushdown(int rt) {
  if (tag[rt]) {
    tag[(rt << 1)] += tag[rt];
    tag[(rt << 1 | 1)] += tag[rt];
    mx[(rt << 1)] += tag[rt];
    mx[(rt << 1 | 1)] += tag[rt];
    tag[rt] = 0;
  }
}
void Update(int pos, int v, int l, int r, int rt) {
  if (l == r) {
    mx[rt] = v;
    tag[rt] = 0;
    return;
  }
  Pushdown(rt);
  int mid = l + r >> 1;
  if (pos <= mid)
    Update(pos, v, l, mid, (rt << 1));
  else
    Update(pos, v, mid + 1, r, (rt << 1 | 1));
  Pushup(rt);
}
void Add(int L, int R, int v, int l, int r, int rt) {
  if (L > R) return;
  if (L <= l && r <= R) {
    tag[rt] += v;
    mx[rt] += v;
    return;
  }
  Pushdown(rt);
  int mid = l + r >> 1;
  if (L <= mid) Add(L, R, v, l, mid, (rt << 1));
  if (mid < R) Add(L, R, v, mid + 1, r, (rt << 1 | 1));
  Pushup(rt);
}
int Query(int L, int R, int l, int r, int rt) {
  if (L > R) return 0;
  if (L <= l && r <= R) return mx[rt];
  Pushdown(rt);
  int mid = l + r >> 1, ans = 0;
  if (L <= mid) ans = max(ans, Query(L, R, l, mid, (rt << 1)));
  if (mid < R) ans = max(ans, Query(L, R, mid + 1, r, (rt << 1 | 1)));
  return ans;
}
void Print(int l, int r, int rt) {
  if (l == r) {
    printf("%d ", mx[rt]);
    return;
  }
  Pushdown(rt);
  int mid = l + r >> 1;
  Print(l, mid, (rt << 1));
  Print(mid + 1, r, (rt << 1 | 1));
}
int main() {
  rd(n), rd(m);
  for (int i = (1); i <= (n); i++) vt[i].push_back(0);
  for (int i = (1); i <= (n); i++) {
    rd(a[i]);
    pos[i] = vt[a[i]][((int)(vt[a[i]]).size()) - 1];
    vt[a[i]].push_back(i);
  }
  for (int j = (1); j <= (m); j++) {
    for (int i = (j); i <= (n); i++) {
      Add(pos[i] + 1, i, 1, 1, n, 1);
      dp[i][j] = Query(j, i, 1, n, 1);
    }
    Update(1, 0, 1, n, 1);
    for (int i = (j); i <= (n - 1); i++) Update(i + 1, dp[i][j], 1, n, 1);
  }
  printf("%d\n", dp[n][m]);
}
