#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
const int MAX_N = 35025;
int maxx[MAX_N << 2], col[MAX_N << 2], pre[MAX_N], last[MAX_N], arr[MAX_N],
    dp[MAX_N][55];
set<int> st;
void up(int rt) { maxx[rt] = max(maxx[rt << 1], maxx[rt << 1 | 1]); }
void down(int rt, int l, int r) {
  if (col[rt]) {
    col[rt << 1] += col[rt];
    col[rt << 1 | 1] += col[rt];
    maxx[rt << 1] += col[rt];
    maxx[rt << 1 | 1] += col[rt];
    col[rt] = 0;
  }
}
void build(int rt, int l, int r, int v) {
  col[rt] = maxx[rt] = 0;
  if (l == r) {
    maxx[rt] = dp[l][v];
    return;
  }
  build(rt << 1, l, ((l + r) >> 1), v);
  build(rt << 1 | 1, ((l + r) >> 1) + 1, r, v);
  up(rt);
}
void update(int rt, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    col[rt]++;
    maxx[rt]++;
    return;
  }
  down(rt, l, r);
  if (x <= ((l + r) >> 1)) update(rt << 1, l, ((l + r) >> 1), x, y);
  if (((l + r) >> 1) < y) update(rt << 1 | 1, ((l + r) >> 1) + 1, r, x, y);
  up(rt);
}
int query(int rt, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    return maxx[rt];
  }
  down(rt, l, r);
  if (y <= ((l + r) >> 1))
    return query(rt << 1, l, ((l + r) >> 1), x, y);
  else if (x > ((l + r) >> 1))
    return query(rt << 1 | 1, ((l + r) >> 1) + 1, r, x, y);
  else
    return max(query(rt << 1, l, ((l + r) >> 1), x, y),
               query(rt << 1 | 1, ((l + r) >> 1) + 1, r, x, y));
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &arr[i]), pre[i] = last[arr[i]], last[arr[i]] = i,
                          st.insert(arr[i]), dp[i][1] = st.size();
  for (int k = 2; k <= m; ++k) {
    build(1, 1, n, k - 1);
    for (int i = k; i <= n; ++i) {
      update(1, 1, n, pre[i], i - 1);
      dp[i][k] = max(dp[i][k - 1], query(1, 1, n, k - 1, i - 1));
    }
  }
  printf("%d\n", dp[n][m]);
  return 0;
}
