<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.*;
import java.util.*;

import static java.math.BigDecimal.valueOf;

public class Solution {
    static MyScanner sc;
    private static PrintWriter out;
    static long M2 = 1_000_000_000L + 7;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();
//
//        stringBuilder.append("50 5\n" +
//                "2 39 16 20 32 36 29 42 14 23 9 4 28 17 45 16 46 1 39 33 47 15 34 43 6 6 12 15 46 11 32 16 31 12 41 33 47 35 22 3 10 4 9 36 22 22 17 33 15 46\n");


//        stringBuilder.append("8 3\n" +
//                "7 7 8 7 7 8 1 7");
//        stringBuilder.append("35000 50 ");
//        Random r = new Random(4);
//        for (int i = 0; i < 35000; i++) {
//            stringBuilder.append(r.nextInt(100) + " ");
//        }

        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }


        out = new PrintWriter(new OutputStreamWriter(System.out));
        initData();
        solve();
//        out.println(time);
        out.flush();
    }


    private static void initData() {

    }

    static long time;

    private static void solve() throws IOException {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = sc.na(n);
        int[] prev = new int[n];
        Arrays.fill(prev, -1);
        HashMap<Integer, Integer> dd = new HashMap<>();
        for (int s = 0; s < n; s++) {
            prev[s] = dd.getOrDefault(a[s], -1);
            dd.put(a[s], s);
        }


        SegmentTree[] m = new SegmentTree[]{new SegmentTree(n + 1), new SegmentTree(n + 1)};
        for (int i = 1; i <= k; i++) {
            m[1].clear();
            for (int l = 0; l < n; l++) {
                m[0].add(prev[l] + 1, l, 1);
                m[1].add(l + 1, l + 1, m[0].max(0, l));
            }
            sw(m, 0, 1);
        }
        out.println(m[0].sum(n, n));
    }

    private static void sw(SegmentTree[] m, int i1, int i2) {
        SegmentTree l = m[i1];
        m[i1] = m[i2];
        m[i2] = l;
    }

    private static final class SegmentTree {
        long[] val1;
        int[] from1;
        int[] to1;
        long[] sum1;
        long[] max1;

        public SegmentTree(int c) {
            c = Math.max(c, 2);
            int size = Integer.highestOneBit(c);
            if (size != c) {
                size <<= 1;
            }
            int rs = size << 1;
            val1 = new long[rs];
            from1 = new int[rs];
            sum1 = new long[rs];
            to1 = new int[rs];
            max1 = new long[rs];

            Arrays.fill(from1, Integer.MAX_VALUE);
            for (int r = val1.length - 1; r > 1; r--) {
                if (r >= size) {
                    from1[r] = r - size;
                    to1[r] = r - size;
                }
                from1[r / 2] = Math.min(from1[r / 2], from1[r]);
                to1[r / 2] = Math.max(to1[r / 2], to1[r]);
            }
        }

        public void clear() {
            Arrays.fill(val1, 0);
            Arrays.fill(sum1, 0);
            Arrays.fill(max1, 0);
        }

        public void add(int from, int to, long val) {
            add(1, from, to, val);
        }

        private void add(int cur, int from, int to, long val) {
            if (cur >= val1.length) return;
            if (from1[cur] > to || from > to1[cur]) {
                return;
            }
            if (from <= from1[cur] && to1[cur] <= to) {
                val1[cur] += val;
                max1[cur] += val;
                return;
            }
            int left = (cur << 1);
            int right = left + 1;
            sum1[cur] += (Math.min(to, to1[cur]) - Math.max(from, from1[cur]) + 1) * val;
            add(left, from, to, val);
            add(right, from, to, val);
            max1[cur] = val1[cur] + Math.max(max1[left], max1[right]);
        }

        public long sum(int from, int to) {
            return sum(1, from, to);
        }

        private long sum(int cur, int from, int to) {
            if (cur >= val1.length) return 0;
            if (from <= from1[cur] && to1[cur] <= to) {
                return val1[cur] * (to1[cur] - from1[cur] + 1) + sum1[cur];
            }
            if (from1[cur] > to || from > to1[cur]) {
                return 0;
            }
            int c1 = Math.max(from, from1[cur]);
            int c2 = Math.min(to, to1[cur]);
            return (c2 - c1 + 1) * val1[cur] + sum((cur << 1) + 1, from, to) + sum(cur << 1, from, to);
        }

        public long max(int from, int to) {
            return max(1, from, to);
        }

        private long max(int cur, int from, int to) {
            if (cur >= val1.length) return 0;
            if (from <= from1[cur] && to1[cur] <= to) {
                return max1[cur];
            }
            if (from1[cur] > to || from > to1[cur]) {
                return 0;
            }
            return Math.max(max((cur << 1) + 1, from, to), max(cur << 1, from, to));
        }
    }


    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

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

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

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

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


}