#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const unordered_set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const unordered_map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const multiset<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  b %= mod;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
int tt[10000100];
int ll[10000100];
int rr[10000100];
int nextfree = 1;
struct pst {
  int nn;
  vector<long long> prev;
  vector<long long> root;
  void createprev(vector<long long>& arr) {
    map<int, int> mp;
    prev.resize(nn);
    for (long long i = 0; i < nn; ++i) {
      prev[i] = mp[arr[i]];
      mp[arr[i]] = i + 1;
    }
  }
  int build(int l, int r) {
    int id = nextfree++;
    tt[id] = 0;
    if (l == r) return id;
    ll[id] = build(l, ((l + r) >> 1));
    rr[id] = build(((l + r) >> 1) + 1, r);
    return id;
  }
  int update(int id, int l, int r, int pos) {
    if (pos < l || pos > r) return id;
    int ID = nextfree++;
    tt[ID] = tt[id] + 1;
    if (l == r) return ID;
    ll[ID] = update(ll[id], l, ((l + r) >> 1), pos);
    rr[ID] = update(rr[id], ((l + r) >> 1) + 1, r, pos);
    return ID;
  }
  int query(int id1, int id2, int l, int r, int lq, int rq) {
    if (lq > r || l > rq) return 0;
    if (lq <= l && r <= rq) {
      return tt[id2] - tt[id1];
    }
    return query(ll[id1], ll[id2], l, ((l + r) >> 1), lq, rq) +
           query(rr[id1], rr[id2], ((l + r) >> 1) + 1, r, lq, rq);
  }
  void init(vector<long long> arr) {
    nn = arr.size();
    createprev(arr);
    root.resize(nn + 1);
    root[0] = build(0, nn);
    for (long long i = 1; i <= nn; ++i) {
      root[i] = update(root[i - 1], 0, nn, prev[i - 1]);
    }
  }
  int getval(int l, int r) {
    return query(root[l - 1], root[r], 0, nn, 0, l - 1);
  }
  void reset() {
    nextfree = 1;
    nn = 0;
    prev.clear();
    root.clear();
  }
} mysol;
long long n, k;
long long dp[51][35050];
void dnc(int k, int l, int r, int opl, int opr) {
  if (l > r) return;
  int mid = (l + r) >> 1;
  int pos = -1;
  dp[k][mid] = -MOD * MOD;
  for (long long i = opl; i <= min(opr, mid); ++i) {
    long long temp = dp[(k - 1)][i - 1] + mysol.getval(i, mid);
    if (temp > dp[k][mid]) {
      dp[k][mid] = temp;
      pos = i;
    }
  }
  dnc(k, l, mid - 1, opl, pos);
  dnc(k, mid + 1, r, pos, opr);
}
void solve() {
  cin >> n >> k;
  vector<long long> arr(n);
  for (long long i = 0; i < n; ++i) cin >> arr[i];
  mysol.init(arr);
  for (long long i = 0; i <= n; ++i) {
    dp[0][i] = -MOD * MOD;
  }
  dp[0][0] = 0;
  for (long long i = 1; i <= k; ++i) {
    dp[i][0] = -MOD * MOD;
    dnc(i, 1, n, 1, n);
  }
  cout << dp[k][n] << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
