#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline void priv(vector<int> a) {
  for (int i = 0; i < ((int)(a).size()); ++i)
    printf("%d%c", a[i], i == (int)(a).size() - 1 ? '\n' : ' ');
}
template <typename T>
istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];
  return i;
}
template <typename T>
string join(const vector<T>& v) {
  stringstream s;
  for (int i = 0; i < ((int)(v).size()); ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
const int MX = 100005, INF = 1001001001;
const long long int LINF = 1e18;
const double eps = 1e-10;
struct X {
  vector<int> d;
  void add(int x) { d.push_back(x); }
  void init() {
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
  }
  int size() const { return (int)(d).size(); }
  int operator[](int i) const { return d[i]; }
  int operator()(int x) const {
    return upper_bound(d.begin(), d.end(), x) - d.begin() - 1;
  }
};
struct F {
  int d;
  F(int d = 0) : d(d) {}
  F operator+(const F& f) const { return F(max(d, f.d)); }
};
struct G {
  int d;
  G(int d = 0) : d(d) {}
  void operator()(F& f) const { f.d += d; }
  void operator*=(const G& g) { d += g.d; }
};
struct seg {
  struct FG {
    F f;
    G g;
    void apply(const G& _g) {
      _g(f);
      g *= _g;
    }
  };
  vector<FG> d;
  int n;
  seg() {}
  seg(int mx) {
    n = 1;
    while (n < mx) n <<= 1;
    d = vector<FG>(n << 1);
  }
  int width(int i) { return 1 << (__builtin_clz(i) - __builtin_clz(n)); }
  void upd(int i) { d[i].f = d[i << 1].f + d[i << 1 | 1].f; }
  FG& operator[](int i) { return d[n + i]; }
  void init() {
    for (int i = (n)-1; i >= 0; --i) upd(i);
  }
  void prop(int i) {
    d[i << 1].apply(d[i].g);
    d[i << 1 | 1].apply(d[i].g);
    d[i].g = G();
  }
  void add(int l, int r, G g) { add(l, r, g, 1, 0, n); }
  void add(int a, int b, const G& g, int i, int l, int r) {
    if (a <= l && r <= b) {
      d[i].apply(g);
      return;
    }
    prop(i);
    int c = (l + r) >> 1;
    if (a < c) add(a, b, g, i << 1, l, c);
    if (c < b) add(a, b, g, i << 1 | 1, c, r);
    upd(i);
  }
  F get(int l, int r) { return get(l, r, 1, 0, n); }
  F get(int a, int b, int i, int l, int r) {
    if (a <= l && r <= b) return d[i].f;
    prop(i);
    int c = (l + r) >> 1;
    F res;
    if (a < c) res = res + get(a, b, i << 1, l, c);
    if (c < b) res = res + get(a, b, i << 1 | 1, c, r);
    return res;
  }
};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n);
  X xs;
  for (int i = 0; i < (n); ++i) scanf("%d", &a[i]), xs.add(a[i]);
  xs.init();
  vector<seg> t(m + 1, seg(n + 5));
  vector<int> pre((int)(xs).size(), -1);
  for (int i = 0; i < (n); ++i) {
    int x = xs(a[i]), p = pre[x];
    if (i) {
      for (int k = (m)-1; k >= 0; --k) {
        t[k + 1].add(i, i + 1, G(t[k].get(0, i).d));
      }
    }
    for (int k = 0; k < (m); ++k) t[k].add(p + 1, i + 1, G(1));
    pre[x] = i;
  }
  int ans = t[m - 1].get(0, n).d;
  cout << ans << endl;
  return 0;
}
