#include <bits/stdc++.h>
using namespace std;
void setIO(const string &name = "") {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  if (name.length()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}
template <typename T>
void read(vector<T> &a) {
  for (auto &x : a) cin >> x;
}
template <typename T>
void read(vector<T> &a, int n) {
  a.resize(n);
  for (auto &x : a) cin >> x;
}
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &v) {
  out << "(";
  out << v.first << "," << v.second;
  return out << ")";
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  for (auto(i) = 0; (i) < ((int)(v).size()); (i)++) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << "]";
}
template <typename T>
void print(vector<T> &a) {
  for (const auto &x : a) cout << x << ' ';
  cout << '\n';
}
void MOD(int &x, int m = 1000000007) {
  x %= m;
  if (x < 0) x += m;
}
template <typename T>
void dbg(const char *name, T &&arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename T, typename... U>
void dbg(const char *names, T &&arg1, U &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  dbg(comma + 1, args...);
}
template <class T>
void read(T &x) {
  cin >> x;
}
template <class T, class... U>
void read(T &t, U &...u) {
  read(t);
  read(u...);
}
template <class T>
void tell(T &x) {
  cout << x;
}
template <class T, class... U>
void tell(T &t, U &...u) {
  tell(t);
  if (sizeof...(u)) tell(" ");
  tell(u...);
}
int gcd(int a, int b) { return !a ? b : gcd(b % a, a); }
struct SegTree {
  int size = 1;
  vector<int> elements, xx;
  void init(int n) {
    while (size < n) size *= 2;
    elements.assign(2 * size, 0);
    xx.assign(2 * size, 0);
  }
  void pull(int x) {
    elements[x] = max(elements[2 * x + 1], elements[2 * x + 2]);
  }
  void push(int x) {
    if (elements[x] == 0) return;
    elements[2 * x + 1] += xx[x];
    elements[2 * x + 2] += xx[x];
    xx[2 * x + 1] += xx[x];
    xx[2 * x + 2] += xx[x];
    xx[x] = 0;
  }
  void add(int l, int r, int v, int x, int lx, int rx) {
    if (l >= rx or r <= lx) return;
    if (l <= lx and rx <= r) {
      elements[x] += v;
      xx[x] += v;
      return;
    }
    push(x);
    int mid = (lx + rx) / 2;
    add(l, r, v, 2 * x + 1, lx, mid);
    add(l, r, v, 2 * x + 2, mid, rx);
    pull(x);
  }
  void add(int l, int r, int v) { add(l, r, v, 0, 0, size); }
  int calc(int l, int r, int x, int lx, int rx) {
    if (l >= rx or r <= lx) return -int(1e9 + 5);
    if (l <= lx and rx <= r) {
      return elements[x];
    }
    push(x);
    int mid = (lx + rx) / 2;
    int r1 = calc(l, r, 2 * x + 1, lx, mid);
    int r2 = calc(l, r, 2 * x + 2, mid, rx);
    pull(x);
    return max(r1, r2);
  }
  int calc(int l, int r) { return calc(l, r, 0, 0, size); }
};
int n, k;
vector<int> a;
vector<int> pos[35002];
int dp[35002][50];
SegTree st[50];
int32_t main() {
  setIO();
  read(n, k);
  read(a, n);
  for (auto(i) = 1; (i) < (k); (i)++) {
    st[i].init(n);
  }
  set<int> s;
  if (true) {
    dp[0][1] = 1;
    pos[a[0]].emplace_back(0);
    s.insert(a[0]);
    for (auto(j) = 1; (j) < (k); (j)++) {
      st[j].add(0, 1, -int(1e9 + 5));
    }
  }
  for (auto(i) = 1; (i) < (n); (i)++) {
    if (true) {
      s.insert(a[i]);
      dp[i][1] = (int)(s).size();
      if (k > 1) {
        if (pos[a[i]].empty()) {
          st[1].add(0, i + 1, 1);
        } else {
          st[1].add(pos[a[i]].back() + 1, i + 1, 1);
        }
        st[1].add(i, i + 1, dp[i - 1][1]);
      }
    }
    for (int j = 2; j <= min(k, i + 1); j++) {
      if (j < k) {
        if (pos[a[i]].empty()) {
          st[j].add(0, i + 1, 1);
        } else {
          st[j].add(pos[a[i]].back() + 1, i + 1, 1);
        }
        st[j].add(i, i + 1, dp[i - 1][j]);
      }
      dp[i][j] = st[j - 1].calc(0, i + 1);
    }
    for (auto(j) = i + 1; (j) < (k); (j)++) {
      st[j].add(i, i + 1, -int(1e9 + 5));
    }
    pos[a[i]].emplace_back(i);
  }
  cout << dp[n - 1][k] << '\n';
  return 0;
}
