<image>

Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.

Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack cakes in boxes, and that the more distinct cake types a box contains (let's denote this number as the value of the box), the higher price it has.

She needs to change the production technology! The problem is that the oven chooses the cake types on its own and Slastyona can't affect it. However, she knows the types and order of n cakes the oven is going to bake today. Slastyona has to pack exactly k boxes with cakes today, and she has to put in each box several (at least one) cakes the oven produced one right after another (in other words, she has to put in a box a continuous segment of cakes).

Slastyona wants to maximize the total value of all boxes with cakes. Help her determine this maximum possible total value.

Input

The first line contains two integers n and k (1 ≤ n ≤ 35000, 1 ≤ k ≤ min(n, 50)) – the number of cakes and the number of boxes, respectively.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) – the types of cakes in the order the oven bakes them.

Output

Print the only integer – the maximum total value of all boxes with cakes.

Examples

Input

4 1
1 2 2 1


Output

2


Input

7 2
1 3 3 1 4 4 4


Output

5


Input

8 3
7 7 8 7 7 8 1 7


Output

6

Note

In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.

In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box, and three in the second box then, so the total value is 5.
#include <bits/stdc++.h>
using namespace std;
double mysqrt(double x) { return max(0.0, sqrt(x)); }
int sgn(double x) {
  if (fabs(x) < 1e-8) return 0;
  if (x < 0)
    return -1;
  else
    return 1;
}
struct point2 {
  double x, y;
  point2() {}
  point2(double _x, double _y) { x = _x, y = _y; }
  point2 operator-(const point2& ne) { return point2(x - ne.x, y - ne.y); }
  point2 operator+(const point2& ne) { return point2(x + ne.x, y + ne.y); }
  point2 operator*(const double t) { return point2(x * t, y * t); }
};
struct line2 {
  point2 a, b;
  line2() {}
  line2(point2 _a, point2 _b) {
    a = _a;
    b = _b;
  }
};
double xmult(point2 a, point2 b) { return a.x * b.y - a.y * b.x; }
double xmult(point2 o, point2 a, point2 b) {
  return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
}
double xmult(double x1, double y1, double x2, double y2) {
  return x1 * y2 - x2 * y1;
}
double dmult(point2 a, point2 b) { return a.x * b.x + a.y * b.y; }
double dmult(point2 o, point2 a, point2 b) {
  return (a.x - o.x) * (b.x - o.x) + (a.y - o.y) * (b.y - o.y);
}
inline int seg_inter(line2 s, line2 p) {
  double minx1 = min(s.a.x, s.b.x), maxx1 = max(s.a.x, s.b.x);
  double minx2 = min(p.a.x, p.b.x), maxx2 = max(p.a.x, p.b.x);
  double miny1 = min(s.a.y, s.b.y), maxy1 = max(s.a.y, s.b.y);
  double miny2 = min(p.a.y, p.b.y), maxy2 = max(p.a.y, p.b.y);
  if ((minx1 > maxx2 + 1e-8) || (minx2 > maxx1 + 1e-8) ||
      (miny1 > maxy2 + 1e-8) || (miny2 > maxy1 + 1e-8))
    return 0;
  else
    return ((xmult(s.a, s.b, p.a) * xmult(s.a, s.b, p.b)) > 1e-8
                ? 1
                : ((xmult(s.a, s.b, p.a) * xmult(s.a, s.b, p.b)) < -1e-8
                       ? (-1)
                       : (0))) <= 0 &&
           ((xmult(p.a, p.b, s.a) * xmult(p.a, p.b, s.b)) > 1e-8
                ? 1
                : ((xmult(p.a, p.b, s.a) * xmult(p.a, p.b, s.b)) < -1e-8
                       ? (-1)
                       : (0))) <= 0;
}
point2 line_intersection(line2 u, line2 v) {
  double a1 = u.b.y - u.a.y, b1 = u.a.x - u.b.x;
  double c1 = u.b.y * (-b1) - u.b.x * a1;
  double a2 = v.b.y - v.a.y, b2 = v.a.x - v.b.x;
  double c2 = v.b.y * (-b2) - v.b.x * a2;
  double D = xmult(a1, b1, a2, b2);
  return point2(xmult(b1, c1, b2, c2) / D, xmult(c1, a1, c2, a2) / D);
}
point2 line_intersection2(line2 u, line2 v) {
  point2 ret = u.a;
  double t = xmult(u.a - v.a, v.b - v.a) / xmult(u.b - u.a, v.b - v.a);
  t = fabs(t);
  ret.x += (u.b.x - u.a.x) * t;
  ret.y += (u.b.y - u.a.y) * t;
  return ret;
}
double lenth(point2 a) { return sqrt(dmult(a, a)); }
double dist(point2 a, point2 b) { return lenth(b - a); }
double dist2(point2 a, point2 b) { return dmult(b - a, b - a); }
bool Seg_inter_line(line2 l1, line2 l2) {
  return sgn(xmult((l2.a - l1.b), (l1.a - l1.b))) *
             sgn(xmult((l2.b - l1.b), (l1.a - l1.b))) <=
         0;
}
bool SegmentProperIntersection(point2 a1, point2 a2, point2 b1, point2 b2) {
  double c1 = xmult(a2 - a1, b1 - a1), c2 = xmult(a2 - a1, b2 - a1);
  double c3 = xmult(b2 - b1, a1 - b1), c4 = xmult(b2 - b1, a2 - b1);
  return sgn(c1) * sgn(c2) < 0 && sgn(c3) * sgn(c4) < 0;
}
int y11, y2, op, n, k, v;
const int maxnode = 150000;
struct SegmentTree {
  int sumv[maxnode];
  int minv[maxnode];
  int maxv[maxnode];
  int addv[maxnode];
  int setv[maxnode];
  void maintain(int o, int L, int R) {
    int lson = o << 1;
    int rson = o << 1 | 1;
    if (R > L) {
      sumv[o] = sumv[lson] + sumv[rson];
      maxv[o] = max(maxv[lson], maxv[rson]);
      minv[o] = min(minv[lson], minv[rson]);
    }
    if (setv[o] >= 0) {
      minv[o] = maxv[o] = setv[o];
      sumv[o] = setv[o] * (R - L + 1);
    }
    if (addv[o]) {
      minv[o] += addv[o];
      maxv[o] += addv[o];
      sumv[o] += addv[o] * (R - L + 1);
    }
  }
  void pushdown(int o) {
    int lson = o << 1;
    int rson = o << 1 | 1;
    if (setv[o] >= 0) {
      setv[lson] = setv[rson] = setv[o];
      addv[lson] = addv[rson] = 0;
      setv[o] = -1;
    }
    if (addv[o]) {
      addv[lson] += addv[o];
      addv[rson] += addv[o];
      addv[o] = 0;
    }
  }
  void update(int o, int L, int R) {
    int lson = o << 1;
    int rson = o << 1 | 1;
    if (y11 <= L && y2 >= R) {
      if (op == 1) {
        addv[o] += v;
      } else {
        setv[o] = v;
        addv[o] = 0;
      }
    } else {
      pushdown(o);
      int m = L + R >> 1;
      if (y11 <= m)
        update(lson, L, m);
      else
        maintain(lson, L, m);
      if (y2 > m)
        update(rson, m + 1, R);
      else
        maintain(rson, m + 1, R);
    }
    maintain(o, L, R);
  }
  void query(int o, int L, int R, int& ssum, int& smin, int& smax) {
    int lson = o << 1;
    int rson = o << 1 | 1;
    maintain(o, L, R);
    if (y11 <= L && y2 >= R) {
      ssum = sumv[o];
      smin = minv[o];
      smax = maxv[o];
    } else {
      pushdown(o);
      int m = L + R >> 1;
      int lsum = 0, lmin = 0x3f3f3f3f, lmax = -0x3f3f3f3f;
      int rsum = 0, rmin = 0x3f3f3f3f, rmax = -0x3f3f3f3f;
      if (y11 <= m) {
        query(lson, L, m, lsum, lmin, lmax);
      } else
        maintain(lson, L, m);
      if (y2 > m) {
        query(rson, m + 1, R, rsum, rmin, rmax);
      } else
        maintain(rson, m + 1, R);
      ssum = lsum + rsum;
      smin = min(lmin, rmin);
      smax = max(lmax, rmax);
    }
  }
};
SegmentTree t;
int dp[60][35111];
int a[35111];
int prec[35111];
int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= k; ++i) {
    op = 2;
    v = 0;
    y11 = 1;
    y2 = n;
    t.update(1, 1, n);
    memset((prec), (0), sizeof(prec));
    for (int j = 1; j <= n; ++j) {
      op = 2;
      v = dp[i - 1][j - 1];
      y11 = y2 = j;
      t.update(1, 1, n);
    }
    for (int j = 1; j <= n; ++j) {
      op = 1;
      v = 1;
      y11 = prec[a[j]] + 1;
      y2 = j;
      t.update(1, 1, n);
      int ssum, smin, smax;
      op = 3;
      y11 = 1;
      y2 = j;
      t.query(1, 1, n, ssum, smin, smax);
      dp[i][j] = smax;
      prec[a[j]] = j;
    }
  }
  printf("%d\n", dp[k][n]);
  return 0;
}
