Problem: You are given a string s of length n consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd.

Calculate the minimum number of operations to delete the whole string s.

Input

The first line contains one integer n (1 ≤ n ≤ 500) — the length of string s.

The second line contains the string s (|s| = n) consisting of lowercase Latin letters.

Output

Output a single integer — the minimal number of operation to delete string s.

Examples

Input


5
abaca


Output


3

Input


8
abcddcba


Output


4

Solution (in JAVA):

Solution:

import java.io.*;
import java.util.*;

public class e2
{
    public static void print(String str,long val){
        System.out.println(str+"  "+val);
    }

    public long gcd(long a, long b) {
        if (b==0L) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    public static void print(Object[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

        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;
        }
    }


    public static void main(String[] args)
    {
        FastReader s=new FastReader();
        int n = s.nextInt();
        String str = s.nextLine();
        char curr = 'A';
        String new_String = "";
        for(int i=0;i<n;i++){
            if(curr!=str.charAt(i)){
                new_String+=str.charAt(i);
                curr = str.charAt(i);
            }
        }
        n = new_String.length();
        char[] string = new_String.toCharArray();
        TreeSet<Integer>[] positions = new TreeSet[26];
        for(int i=0;i<26;i++){
            positions[i] = new TreeSet<>();
        }
        for(int i=0;i<n;i++){
            positions[string[i]-'a'].add(i);
        }
//        print(positions);
        int[][] dp = new int[n][n];
        int MAX_VALUE = (int)(1e5);
        for(int i=0;i<n;i++){
            Arrays.fill(dp[i],MAX_VALUE);
            dp[i][i] = 1;
        }
        for(int size = 2;size<=n;size++){
            for(int i=0;i+size-1<n;i++){
                char ch = string[i];
                int next = i+size-1;
//                if(i<(n-1)){
                    dp[i][next] = 1+dp[i+1][next];
//                }
                if(i==positions[ch-'a'].last()){
                    continue;
                }
//                print(i+" ",size);
                int cur = positions[ch-'a'].higher(i);
                while (cur<=next){
                    dp[i][next] = Math.min(dp[i+1][cur-1]+dp[cur][next],dp[i][next]);
//                    print(cur+" dp ",dp[i][next]);
                    if(cur == positions[ch-'a'].last()){
                        break;
                    }
                    else {
                        cur = positions[ch-'a'].higher(cur);
                    }
                }
            }
        }
//        debug(dp);

        System.out.println(dp[0][n-1]);
    }




//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//              out.write((arr[i]+" ").getBytes());
//         }
//        out.flush();
//  long start_time = System.currentTimeMillis();
//  long end_time = System.currentTimeMillis();
//  System.out.println((end_time - start_time) + "ms");



}