#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
const int MAXINT = 2147483640;
const int MAXLL = 9223372036854775800LL;
const int MAXN = 1000000;
const double pi = 3.1415926535897932384626433832795;
using namespace std;
int x1[300000];
int t[300000];
int g[300000];
int dp[36000][61];
int f[61][36000];
void push(int v) {
  t[v * 2] += g[v];
  t[v * 2 + 1] += g[v];
  g[v * 2] += g[v];
  g[v * 2 + 1] += g[v];
  g[v] = 0;
  return;
}
void modify(int v, int tl, int tr, int l, int r, int val) {
  if (l > r) return;
  if (tl == l and tr == r) {
    g[v] += val;
    t[v] += val;
  } else {
    int tm = (tl + tr) / 2;
    push(v);
    modify(v * 2, tl, tm, l, min(r, tm), val);
    modify(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
void modify1(int v, int tl, int tr, int l, int r, int val) {
  if (l > r) return;
  if (tl == l and tr == r)
    t[v] = val, g[v] = val;
  else {
    int tm = (tl + tr) / 2;
    push(v);
    modify1(v * 2, tl, tm, l, min(r, tm), val);
    modify1(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
int get(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (tl == l and tr == r) return t[v];
  int tm = (tl + tr) / 2;
  push(v);
  return max(get(v * 2, tl, tm, l, min(r, tm)),
             get(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  srand(time(0));
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x1[i];
    if (!f[1][x1[i]])
      dp[i][1] = dp[i - 1][1] + 1;
    else
      dp[i][1] = dp[i - 1][1];
    f[1][x1[i]] = i;
  }
  for (int j = 2; j <= k; j++) {
    for (int i = 1; i <= 4 * n; i++) t[i] = 0, g[i] = 0;
    for (int i = 1; i <= n; i++) {
      modify1(1, 1, n, i, i, dp[i - 1][j - 1]);
      modify(1, 1, n, f[j][x1[i]] + 1, i, 1);
      f[j][x1[i]] = i;
      dp[i][j] = get(1, 1, n, 1, i);
    }
  }
  cout << dp[n][k] << endl;
  return 0;
}
