<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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class B3 {

    private static final long MODULO = (long) (1e9 + 7);
    private static final int INF = (int) 1e9;
    private static int[] a;
    private static int[][] f;
    private static int[] next; // next[cake_type]: next index of cake with cake_type
    private static int n;
    private static int[][] tree;

    public static void main(String[] args) {
        BufferedScanner scanner = new BufferedScanner();
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

        int t = 1;//scanner.nextInt();
        for (int tc = 0; tc < t; tc++) {
            n = scanner.nextInt();//35000;//
            int k = scanner.nextInt();//50;//
            a = new int[n];
            Random r = new Random();
            for (int i = 0; i < n; i++) {
                a[i] = scanner.nextInt() - 1;//Math.abs(r.nextInt()) % n;//
            }
//            for (int i = 0; i < n; i++) {
//                System.err.print(i + " ");
//            }
//            System.err.println();
            long timer = System.nanoTime();
            f = new int[k + 1][n];
            next = new int[n];
            {
                int[] latest = new int[n];
                Arrays.fill(latest, -1);
                for (int i = n - 1; i >= 0; i--) {
                    if (latest[a[i]] == -1) {
                        next[i] = INF;
                    } else {
                        next[i] = latest[a[i]];
                    }
                    latest[a[i]] = i;
                }
            }
            build();
            System.err.println("build finished: " + (System.nanoTime() - timer) / 1e9);
            timer = System.nanoTime();
            for (int i = 0; i < n; i++) {
                f[1][i] = distinct(0, i);
//                System.err.println("f[1][" + i + "]=" + f[1][i]);
            }
            for (int box = 2; box <= k; box++) {
//                System.err.println("box: " + box);
                compute(box, 0, n - 1, 0, n - 1);
            }
            writer.println(f[k][n - 1]);
            System.err.println((System.nanoTime() - timer) / 1e9);
            System.err.println("total=" + total);
            System.err.println("total1=" + total1);
        }

        scanner.close();
        writer.flush();
        writer.close();
    }

    private static void build() {
        tree = new int[4 * n][];
        build(0, 0, n - 1);
    }

    private static void build(int root, int left, int right) {
        if (left > right) {
            return;
        }
        tree[root] = new int[right - left + 1];
        System.arraycopy(next, left, tree[root], 0, tree[root].length);
        Arrays.sort(tree[root]);
        if (left < right) {
            int mid = (left + right) / 2;
            build(root * 2 + 1, left, mid);
            build(root * 2 + 2, mid + 1, right);
        }
    }

    static long total = 0, total1 = 0;

    private static void compute(int box, int left, int right, int optL, int optR) {
        if (left > right) {
            return;
        }
        int mid = (left + right) >> 1;
        int best = 0, opt = -1;
        int realR = Math.min(mid, optR);
        int d = distinct(realR + 1, mid);
        // f[box][mid];
        for (int i = realR; i >= optL; i--) {
            total1++;
            int work = f[box - 1][i] + d;
            if (work >= best) {
                best = work;
                opt = i;
            }
            if (next[i] > mid) {
                d++;
            }
        }
        f[box][mid] = best;
        compute(box, left, mid - 1, optL, opt);
        compute(box, mid + 1, right, opt, optR);
    }

    private static int distinct(int left, int right) {
        if (left > right) {
            return 0;
        } else {
            int d = query(0, 0, n - 1, left, right, right);
//            System.err.println("left = " + left + ", right = " + right + ", dist=" + d);
            return d;
        }
    }

    private static int query(int root, int low, int high, int qLow, int qHigh, int key) {
        if (qHigh < low || high < qLow) {
            return 0;
        }
        if (qLow <= low && high <= qHigh) {
            return upperBound(tree[root], key);
        }
        int mid = (low + high) / 2;
        return query(root * 2 + 1, low, mid, qLow, qHigh, key)
                + query(root * 2 + 2, mid + 1, high, qLow, qHigh, key);
    }

    private static int upperBound(int[] a, int key) {
        int i = Arrays.binarySearch(a, key);
        if (i >= 0) {
            i++;
        } else {
            i = -(i + 1);
        }
        return a.length - i;
    }

    public static class BufferedScanner {
        BufferedReader br;
        StringTokenizer st;

        public BufferedScanner(Reader reader) {
            br = new BufferedReader(reader);
        }

        public BufferedScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }
        while (b > 0) {
            long tmp = b;
            b = a % b;
            a = tmp;
        }
        return a;
    }

    static long inverse(long a, long m) {
        long[] ans = extgcd(a, m);
        return ans[0] == 1 ? (ans[1] + m) % m : -1;
    }

    private static long[] extgcd(long a, long m) {
        if (m == 0) {
            return new long[]{a, 1, 0};
        } else {
            long[] ans = extgcd(m, a % m);
            long tmp = ans[1];
            ans[1] = ans[2];
            ans[2] = tmp;
            ans[2] -= ans[1] * (a / m);
            return ans;
        }
    }

    static long add(long a, long b) {
        a += b;
        if (a >= MODULO) {
            a -= MODULO;
        }
        return a;
    }

    static long sub(long a, long b) {
        a -= b;
        if (a < 0) {
            a += MODULO;
        }
        return a;
    }

    static long mul(long a, long b) {
        return a * b % MODULO;
    }

    static long div(long a, long b) {
        return a * inverse(b, MODULO) % MODULO;
    }

    static class Comb {
        final long modulo;
        final long[] fac, fnv;

        Comb(int limit, long modulo) {
            fac = new long[limit + 1];
            fnv = new long[limit + 1];
            fac[0] = 1;
            fnv[0] = 1;
            for (int i = 1; i <= limit; i++) {
                fac[i] = mul(fac[i - 1], i);
                fnv[i] = div(fnv[i - 1], i);
            }
            this.modulo = modulo;
        }

        long c(int total, int choose) {
            if (total < choose) {
                return 0;
            }
            if (total == 0 || total == choose) {
                return 1;
            }
            return mul(mul(fac[total], fnv[choose]), fnv[total - choose]);
        }
    }

}
