<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.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public int[][] dp;
        public int[][] opt;
        public int[] arr;
        public HashMap<Pair<Integer, Integer>, Integer> pp;
        public TaskB.SegmentTree root;
        public static int[] seq;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            arr = new int[n + 1];
            for (int i = 1; i <= n; i++) arr[i] = in.nextInt();
            int[] next = new int[n + 1];
            Arrays.fill(next, n + 1);

            seq = new int[n + 1];
            for (int i = n; i >= 1; i--) {
                seq[i] = next[arr[i]];
                next[arr[i]] = i;
            }

            dp = new int[k + 1][n + 1];
            opt = new int[k + 1][n + 1];

            root = new TaskB.SegmentTree(1, n);
            pp = new HashMap<>();
            for (int i = 1; i <= k; i++) {
                compute(i, 1, n, 1, n);
            }
            out.println(dp[k][n]);
        }

        public void solveOne(int a, int b, int from, int to) {
            to = Math.min(to, b);
            if (to < from) return;
            int ee = cost(to + 1, b);
            int add = 0;
            for (int j = to; j >= from; j--) {
                if (j <= b && seq[j] > b) add++;
                int t = dp[a - 1][j - 1] + ee + add;
                if (t > dp[a][b]) {
                    dp[a][b] = t;
                    opt[a][b] = j;
                }
            }
        }

        public void compute(int d, int L, int R, int optL, int optR) {
            if (L > R) return;
            if (L == R) {
                solveOne(d, L, optL, optR);
                return;
            }
            optR = Math.min(optR, R);
            if (optL == optR) {
                for (int i = L; i <= R; i++) {
                    solveOne(d, i, optL, optR);
                }
                return;
            }

            int M = (L + R) / 2;
            solveOne(d, M, optL, optR);
            compute(d, L, M - 1, optL, opt[d][M]);
            compute(d, M + 1, R, opt[d][M], optR);
        }

        public int cost(int from, int to) {
            if (from > to) return 0;
            Pair<Integer, Integer> key = new Pair<>(from, to);
            Integer d = pp.get(key);
            if (d != null) return d;
            int res = root.query(from, to, to);
            pp.put(key, res);
            return res;
        }

        static class SegmentTree {
            public int[] arr;
            public int start;
            public int end;
            public TaskB.SegmentTree lchild;
            public TaskB.SegmentTree rchild;

            public SegmentTree(int start, int end) {
                this.start = start;
                this.end = end;
                arr = new int[end - start + 2];
                arr[0] = -1;
                if (start == end) {
                    arr[1] = seq[start];
                } else {
                    int mid = (start + end) >> 1;
                    lchild = new TaskB.SegmentTree(start, mid);
                    rchild = new TaskB.SegmentTree(mid + 1, end);
                    int lidx = 1, ridx = 1;

                    int idx = 1;
                    int[] larr = lchild.arr, rarr = rchild.arr;
                    while (lidx < larr.length && ridx < rarr.length) {
                        if (larr[lidx] < rarr[ridx]) {
                            arr[idx++] = larr[lidx++];
                        } else {
                            arr[idx++] = rarr[ridx++];
                        }
                    }
                    while (lidx < larr.length) {
                        arr[idx++] = larr[lidx++];
                    }
                    while (ridx < rarr.length) {
                        arr[idx++] = rarr[ridx++];
                    }
                }
            }

            public int query(int s, int e, int k) {
                if (start == s && end == e) {
                    int lo = 0, hi = arr.length;
                    while (lo < hi) {
                        int mid = (lo + hi) / 2;
                        if (arr[mid] <= k) lo = mid + 1;
                        else hi = mid;
                    }
                    return arr.length - lo;
                }
                int mid = (start + end) >> 1;
                if (mid >= e) return lchild.query(s, e, k);
                else if (mid < s) return rchild.query(s, e, k);
                else {
                    int x = lchild.query(s, mid, k);
                    x += rchild.query(mid + 1, e, k);
                    return x;
                }
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }

    static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public final U u;
        public final V v;

        public Pair(U u, V v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            return (u == null ? 0 : u.hashCode() * 31) + (v == null ? 0 : v.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (u == null ? p.u == null : u.equals(p.u)) && (v == null ? p.v == null : v.equals(p.v));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = u.compareTo(b.u);
            return cmpU != 0 ? cmpU : v.compareTo(b.v);
        }

        public String toString() {
            return String.format("[Pair = (%s, %s)", u.toString(), v.toString());
        }

    }
}

