#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b);

#define lint long long
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define lint long long

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b);

typedef vector < int > vi ;
typedef pair < int, int > pii ;

// template <typename T>
int modpow(int base, int exp, int modulo) {
  base %= modulo;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulo;
    base = (base * base) % modulo;
    exp >>= 1;
  }
  return result;
}

const int N = 2e6 + 2 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;
const int LN = 20 ;

// int after[20], before[20] ;
string s ;
int n, m ;
int cnt[21][21] ;
int dp[LN][N] ;

int solve(int pos, int mask)
{
    if(pos < 0) return 0;
    if(dp[pos][mask] != -1) return dp[pos][mask] ;

    int ans = 1e9 ;
    for(int i = 0; i < m; i++)
    {
        if(!(mask & (1 << i)))
        {
            int marks = 0 ;
            int aft = 0, bef = 0 ;
            for(int j = 0; j < m; j++)
            {
                if(j == i) continue ;
                if(mask & (1 << j))
                    aft += cnt[i][j] ;
                else
                    bef += cnt[i][j] ;
            }
            marks += (bef * (pos + 1)); marks -= (aft * (pos + 1));
            ans = min(ans, marks + solve(pos - 1, mask | (1 << i) ) ) ;
        }
    }
    return dp[pos][mask] = ans ;
}

int main()
{
    cin >> n >> m >> s ; memset(cnt, 0, sizeof(cnt));
    for(int i = 1; i < n; i++)
    {
        int cur = s[i] - 'a', prev = s[i - 1] - 'a' ;
        cnt[cur][prev]++, cnt[prev][cur]++ ;
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(m-1, 0);
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b);

#define lint long long
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define lint long long

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b);

typedef vector < int > vi ;
typedef pair < int, int > pii ;

// template <typename T>
int modpow(int base, int exp, int modulo) {
  base %= modulo;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulo;
    base = (base * base) % modulo;
    exp >>= 1;
  }
  return result;
}

const int N = 2e5 + 2 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;
const int LN = 20 ;

int after[20], before[20] ;
string s ;
int n, m ;
int cnt[21][21] ;
int dp[LN][N] ;

int solve(int pos, int mask)
{
    if(pos < 0) return 0;
    if(dp[pos][mask] != -1) return dp[pos][mask] ;

    int ans = 1e9 ;
    for(int i = 0; i < m; i++)
    {
        if(!(mask & (1 << i)))
        {
            int marks = 0 ;
            int aft = 0, bef = 0 ;
            for(int j = 0; j < m; j++)
            {
                if(mask & (1 << j))
                    aft += cnt[i][j] ;
                else
                    bef += cnt[i][j] ;
            }
            marks -= (aft * pos); marks += (bef * pos);
            ans = min(ans, marks + solve(pos - 1, mask | (1 << i) ) ) ;
        }
    }
    return dp[pos][mask] = ans ;
}

int main()
{
    cin >> n >> m >> s ; memset(cnt, 0, sizeof(cnt));
    for(int i = 1; i < n; i++)
    {
        int cur = s[i] - 'a', prev = s[i - 1] - 'a' ;
        cnt[cur][prev]++, cnt[prev][cur]++ ;
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(m-1, 0);
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    vector<int> continued_cost(1 << M, 0);
    dp[0] = 0;
    for (int m : masks) {
        for (int i = 0; i < M; ++i) {
            if (((1 << i) & m) == 0) {
                int nxt = (1 << i) + m;
                dp[nxt] = min(dp[nxt], dp[m] + continued_cost[m]);

                continued_cost[nxt] = continued_cost[m];
                for (int j = 0; j < M; ++j) {
                    if (j != i) {
                        if (((1 << j) & m) == 0) {
                            continued_cost[nxt] += freq[i][j];
                        } else {
                            continued_cost[nxt] -= freq[i][j];
                        }
                    }
                }
            }
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    dp[0] = 0;
    for (int m : masks) {
        int continued_cost = 0;
        vector<int> use, notuse;
        for (int i = 0; i < M; ++i) {
            if (((1 << i) & m) > 0) {
                use.push_back(i);
            } else {
                notuse.push_back(i);
            }
        }
        for (int i : use) {
            for (int j : notuse) {
                continued_cost += freq[i][j];
            }
        }

        for (int i = 0; i < M; ++i) {
            if (((1 << i) & m) == 0) {
                int nxt = (1 << i) + m;
                dp[nxt] = min(dp[nxt], dp[m] + continued_cost);
            }
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    vector<int> continued_cost(1 << M, -1);
    dp[0] = 0;
    continued_cost[0] = 0;
    for (int m : masks) {
        for (int i = 0; i < M; ++i) {
            if (((1 << i) & m) == 0) {
                int nxt = (1 << i) + m;
                dp[nxt] = min(dp[nxt], dp[m] + continued_cost[m]);

                if (continued_cost[nxt] == -1) {
                    continued_cost[nxt] = continued_cost[m];
                    for (int j = 0; j < M; ++j) {
                        if (j != i) {
                            if (((1 << j) & m) == 0) {
                                continued_cost[nxt] += freq[i][j];
                            } else {
                                continued_cost[nxt] -= freq[i][j];
                            }
                        }
                    }
                }
            }
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    dp[0] = 0;
    for (int m : masks) {
        int continued_cost = 0;
        for (int i = 0; i < M; ++i) {
            if ((m >> i) & 1) {
                for (int j = 0; j < M; ++j) {
                    if (((m >> j) & 1) == 0) {
                        continued_cost += freq[i][j];
                    }
                }
            }
        }

        for (int i = 0; i < M; ++i) {
            if (((1 << i) & m) == 0) {
                int nxt = (1 << i) + m;
                dp[nxt] = min(dp[nxt], dp[m] + continued_cost);
            }
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    dp[0] = 0;
    for (int m = 0; m < 1 << M; m++) {
        int continued_cost = 0;
        for (int i = 0; i < M; ++i) {
            if ((m >> i) & 1) {
                for (int j = 0; j < M; ++j) {
                    if (((m >> j) & 1) == 0) {
                        continued_cost += freq[i][j];
                    }
                }
            }
        }

        for (int i = 0; i < M; ++i) {
            int nxt = (1 << i) | m;
            dp[nxt] = min(dp[nxt], dp[m] + continued_cost);
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    dp[0] = 0;
    for (int m : masks) {
        int continued_cost = 0;
        for (int i = 0; i < M; ++i) {
            if ((m >> i) & 1) {
                for (int j = 0; j < M; ++j) {
                    if (((m >> j) & 1) == 0) {
                        continued_cost += freq[i][j];
                    }
                }
            }
        }

        for (int i = 0; i < M; ++i) {
            int nxt = (1 << i) | m;
            dp[nxt] = min(dp[nxt], dp[m] + continued_cost);
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> dp(1 << M, INF);
    dp[0] = 0;
    for (int m = 0; m < 1 << M; m++) {
        int continued_cost = 0;
        for (int i = 0; i < M; ++i) {
            if ((m >> i) & 1) {
                for (int j = 0; j < M; ++j) {
                    if (((m >> j) & 1) == 0) {
                        continued_cost += freq[i][j];
                    }
                }
            }
        }

        for (int i = 0; i < M; ++i) {
            int nxt = (1 << i) | m;
            dp[nxt] = min(dp[nxt], dp[m] + continued_cost);
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    vector<int> continued_cost(1 << M, 0);
    dp[0] = 0;
    for (int m : masks) {
        for (int i = 0; i < M; ++i) {
            if (((1 << i) & m) == 0) {
                int nxt = (1 << i) + m;
                dp[nxt] = min(dp[nxt], dp[m] + continued_cost[m]);

                if (continued_cost[nxt] == 0) {
                    continued_cost[nxt] = continued_cost[m];
                    for (int j = 0; j < M; ++j) {
                        if (j != i) {
                            if (((1 << j) & m) == 0) {
                                continued_cost[nxt] += freq[i][j];
                            } else {
                                continued_cost[nxt] -= freq[i][j];
                            }
                        }
                    }
                }
            }
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    dp[0] = 0;
    for (int m : masks) {
        int continued_cost = 0;
        for (int i = 0; i < M; ++i) {
            if ((m >> i) & 1) {
                for (int j = 0; j < M; ++j) {
                    if (((m >> j) & 1) == 0) {
                        continued_cost += freq[i][j];
                    }
                }
            }
        }

        for (int i = 0; i < M; ++i) {
            int nxt = (1 << i) + m;
            dp[nxt] = min(dp[nxt], dp[m] + continued_cost);
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1023456789;

int bitcount(int x) {
    int n = 0;
    while (x) {
        n += (x & 1);
        x >>= 1;
    }
    return n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> freq(M, vector<int>(M, 0));
    for (int i = 1; i < N; ++i) {
        int a = s[i] - 'a';
        int b = s[i - 1] - 'a';
        freq[a][b]++;
        freq[b][a]++;
    }

    vector<int> masks(1 << M);
    for (int i = 0; i < (1 << M); ++i) {
        masks[i] = i;
    }
    sort(masks.begin(), masks.end(), [](int i, int j) {
        return bitcount(i) < bitcount(j);
    });

    vector<int> dp(1 << M, INF);
    dp[0] = 0;
    for (int m : masks) {
        int continued_cost = 0;
        for (int i = 0; i < M; ++i) {
            if (((1 << i) & m) > 0) {
                for (int j = 0; j < M; ++j) {
                    if (((1 << j) & m) == 0) {
                        continued_cost += freq[i][j];
                    }
                }
            }
        }

        for (int i = 0; i < M; ++i) {
            if (((1 << i) & m) == 0) {
                int nxt = (1 << i) + m;
                dp[nxt] = min(dp[nxt], dp[m] + continued_cost);
            }
        }
    }

    cout << dp[(1 << M) - 1] << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define timepass (mod + 2)
#define MAXN 500000 + 5
#define LOGN 20
#define over ((1ll << 32))
using namespace std;
#define N 2005

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int ll
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define sp(a , x) cout << fixed << setprecision(a) << x << endl;
#define si(temp) (ll)temp.size()
#define len(temp) (ll)temp.length()
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define pi acos(-1)
#define con continue
#define endl "\n"
#define w(q) while(q--)

//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl

typedef pair<int , int> pii;
typedef pair<int , pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

int ansdp[1ll << 21];
int costdp[1ll << 21];

int dp[21][21];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    int &ans = costdp[mask];
    if (ans != -1)
        return ans;
    //cout << mask << "enter 1 " << endl;
    ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (ans);
}

int rec(int mask , int m)
{
    int c = __builtin_popcountll(mask);
    if (c == m)
        return 0;
    int &ans = ansdp[mask];
    if (ans != -1)
        return ans;
    int cost = reccost(mask , m);
    ans = LLONG_MAX;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask & (1ll << j))
            continue;
        ans = min(ans , rec(mask | (1ll << j) , m));
    }
    ans += cost;
    return (ans);
}
signed main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 7 ; i++)
    //     trace2(i , costdp[i]);
    return 0;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int ansdp[1ll << 20];
int costdp[1ll << 20];

int dp[20][20];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    int &ans = costdp[mask];
    if (ans != -1)
        return ans;
    //cout << mask << "enter 1 " << endl;
    ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (ans);
}

int rec(int mask , int m)
{
    int c = __builtin_popcountll(mask);
    if (c == m)
        return 0;
    int &ans = ansdp[mask];
    if (ans != -1)
        return ans;
    int cost = reccost(mask , m);
    ans = 1e9;
    //cout << mask << endl;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask >> j & 1ll)
            continue;
        ans = min(ans , rec((mask | (1ll << j)) , m));
    }
    ans += cost;
    return (ans);
}
int main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 255 ; i++)
    //     trace2(i , ansdp[i]);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define timepass (mod + 2)
#define MAXN 500000 + 5
#define LOGN 20
#define over ((1ll << 32))
using namespace std;
#define N 2005

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int ll
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define sp(a , x) cout << fixed << setprecision(a) << x << endl;
#define si(temp) (ll)temp.size()
#define len(temp) (ll)temp.length()
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define pi acos(-1)
#define con continue
#define endl "\n"
#define w(q) while(q--)

//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl

typedef pair<int , int> pii;
typedef pair<int , pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

int ansdp[1ll << 21];
int costdp[1ll << 21];

int dp[21][21];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    int &ans = costdp[mask];
    if (ans != -1)
        return ans;
    //cout << mask << "enter 1 " << endl;
    ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (ans);
}

int rec(int mask , int m)
{
    if (mask == ((1ll << m) - 1))
        return 0;
    int &ans = ansdp[mask];
    if (ans != -1)
        return ans;
    int cost = reccost(mask , m);
    ans = LLONG_MAX;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask & (1ll << j))
            continue;
        ans = min(ans , rec(mask | (1ll << j) , m));
    }
    ans += cost;
    return (ans);
}
signed main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 7 ; i++)
    //     trace2(i , costdp[i]);
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define timepass (mod + 2)
#define MAXN 500000 + 5
#define LOGN 20
#define over ((1ll << 32))
using namespace std;
#define N 2005

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int ll
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define sp(a , x) cout << fixed << setprecision(a) << x << endl;
#define si(temp) (ll)temp.size()
#define len(temp) (ll)temp.length()
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define pi acos(-1)
#define con continue
#define endl "\n"
#define w(q) while(q--)

//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl

typedef pair<int , int> pii;
typedef pair<int , pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

int ansdp[1ll << 20];
int costdp[1ll << 20];

int dp[20][20];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    int &ans = costdp[mask];
    if (ans != -1)
        return ans;
    //cout << mask << "enter 1 " << endl;
    ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (ans);
}

int rec(int mask , int m)
{
    int c = __builtin_popcountll(mask);
    if (c == m)
        return 0;
    int &ans = ansdp[mask];
    if (ans != -1)
        return ans;
    int cost = reccost(mask , m);
    ans = LLONG_MAX;
    //cout << mask << endl;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask >> j & 1ll)
            continue;
        ans = min(ans , rec((mask | (1ll << j)) , m));
    }
    ans += cost;
    return (ans);
}
signed main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 255 ; i++)
    //     trace2(i , ansdp[i]);
    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int ansdp[1ll << 20];
int costdp[1ll << 20];

int dp[20][20];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    int &ans = costdp[mask];
    if (ans != -1)
        return ans;
    //cout << mask << "enter 1 " << endl;
    ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (ans);
}

int rec(int mask , int m)
{
    int c = __builtin_popcountll(mask);
    if (c == m)
        return 0;
    int &ans = ansdp[mask];
    if (ans != -1)
        return ans;
    int cost = reccost(mask , m);
    ans = LLONG_MAX;
    //cout << mask << endl;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask >> j & 1ll)
            continue;
        ans = min(ans , rec((mask | (1ll << j)) , m));
    }
    ans += cost;
    return (ans);
}
signed main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 255 ; i++)
    //     trace2(i , ansdp[i]);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define timepass (mod + 2)
#define MAXN 500000 + 5
#define LOGN 20
#define over ((1ll << 32))
using namespace std;
#define N 2005

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int ll
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define sp(a , x) cout << fixed << setprecision(a) << x << endl;
#define si(temp) (ll)temp.size()
#define len(temp) (ll)temp.length()
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define pi acos(-1)
#define con continue
#define endl "\n"
#define w(q) while(q--)

//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl

typedef pair<int , int> pii;
typedef pair<int , pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

int ansdp[1ll << 20];
int costdp[1ll << 20];

int dp[20][20];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    int &ans = costdp[mask];
    if (ans != -1)
        return ans;
    //cout << mask << "enter 1 " << endl;
    ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (ans);
}

int rec(int mask , int m)
{
    int c = __builtin_popcountll(mask);
    if (c == m)
        return 0;
    int &ans = ansdp[mask];
    if (ans != -1)
        return ans;
    int cost = reccost(mask , m);
    ans = LLONG_MAX;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask & (1ll << j))
            continue;
        ans = min(ans , rec(mask | (1ll << j) , m));
    }
    ans += cost;
    return (ans);
}
signed main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 7 ; i++)
    //     trace2(i , costdp[i]);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define timepass (mod + 2)
#define MAXN 500000 + 5
#define LOGN 20
#define over ((1ll << 32))
using namespace std;
#define N 2005

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int ll
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define sp(a , x) cout << fixed << setprecision(a) << x << endl;
#define si(temp) (ll)temp.size()
#define len(temp) (ll)temp.length()
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define pi acos(-1)
#define con continue
#define endl "\n"
#define w(q) while(q--)

//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl

typedef pair<int , int> pii;
typedef pair<int , pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

int ansdp[1ll << 20];
int costdp[1ll << 20];

int dp[20][20];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    int &ans = costdp[mask];
    if (ans != -1)
        return ans;
    //cout << mask << "enter 1 " << endl;
    ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (ans);
}

int rec(int mask , int m)
{
    int c = __builtin_popcountll(mask);
    if (c == m)
        return 0;
    int &ans = ansdp[mask];
    if (ans != -1)
        return ans;
    int cost = reccost(mask , m);
    ans = LLONG_MAX;
    //cout << mask << endl;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask >> j & 1ll)
            continue;
        ans = min(ans , rec((mask | (1ll << j)) , m));
    }
    ans += cost;
    return (ans);
}
signed main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 255 ; i++)
    //     trace2(i , ansdp[i]);
    return 0;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int ansdp[1ll << 20];
int costdp[1ll << 20];

int dp[20][20];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    int &ans = costdp[mask];
    if (ans != -1)
        return ans;
    //cout << mask << "enter 1 " << endl;
    ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (ans);
}

int rec(int mask , int m)
{
    int c = __builtin_popcountll(mask);
    if (c == m)
        return 0;
    int &ans = ansdp[mask];
    if (ans != -1)
        return ans;
    int cost = reccost(mask , m);
    ans = LLONG_MAX;
    //cout << mask << endl;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask >> j & 1ll)
            continue;
        ans = min(ans , rec((mask | (1ll << j)) , m));
    }
    ans += cost;
    return (ans);
}
int main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 255 ; i++)
    //     trace2(i , ansdp[i]);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define timepass (mod + 2)
#define MAXN 500000 + 5
#define LOGN 20
#define over ((1ll << 32))
using namespace std;
#define N 2005

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int ll
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define sp(a , x) cout << fixed << setprecision(a) << x << endl;
#define si(temp) (ll)temp.size()
#define len(temp) (ll)temp.length()
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define pi acos(-1)
#define con continue
#define endl "\n"
#define w(q) while(q--)

//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl

typedef pair<int , int> pii;
typedef pair<int , pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

int ansdp[1ll << 21];
int costdp[1ll << 21];

int dp[21][21];

int reccost(int mask , int m)
{
    //cout << mask << " enter " << endl;
    if (mask == 0)
        return (costdp[mask] = 0);
    if (mask == (1ll << m) - 1)
        return (costdp[mask] = 0);
    if (costdp[mask] != -1)
        return costdp[mask];
    //cout << mask << "enter 1 " << endl;
    int ans = 0;
    for (int i = 0 ; i < m ; i++)
    {
        for (int j = i + 1 ; j < m ; j++)
        {
            if ((mask >> i & 1) ^ (mask >> j & 1))
            {
                ans += dp[i][j];
            }
        }
    }
    return (costdp[mask] = ans);
}

int rec(int mask , int m)
{
    if (mask == ((1ll << m) - 1))
        return 0;
    if (ansdp[mask] != -1)
        return ansdp[mask];
    int cost = reccost(mask , m);
    int ans = LLONG_MAX;
    for (int j = 0 ; j < m ; j++)
    {
        if (mask & (1ll << j))
            continue;
        ans = min(ans , rec(mask | (1ll << j) , m));
    }
    ans += cost;
    return (ansdp[mask] = ans);
}
signed main()
{
    FAST;
    memset(dp , 0 , sizeof dp);
    memset(ansdp , -1 , sizeof ansdp);
    memset(costdp , -1 , sizeof costdp);
    int n , m;
    cin >> n >> m;
    string str;
    cin >> str;
    for (int i = 1 ; i < n ; i++)
    {
        int c1 = str[i] - 'a';
        int c2 = str[i - 1] - 'a';
        dp[c1][c2]++;
        dp[c2][c1]++;
    }
    // for (int i = 0 ; i <= 2 ; i++)
    //     for (int j = 0 ; j <= 2 ; j++)
    //         cout << dp[i][j] << " \n"[j == 2];
    cout << rec(0 , m) << endl;
    // for (int i = 0 ; i <= 7 ; i++)
    //     trace2(i , costdp[i]);
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807ll
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define N  100005

ll n,m;
string s;
ll arr[20][20];
ll dp[(1<<20)];
ll full;
unordered_map<ll,ll>lol;
int cnti[(1<<20)][20];
ll dps(ll mask)
{
    if(dp[mask]!=-1)
        return dp[mask];
    ll ans=hell;
    ll rem=full^mask;
    if(rem==0)
        return 0;
    ll cnt=__builtin_popcount(mask);
    ll x=rem;
    vi off,on;
    rep(i,0,m)
    {
        if(mask&(1<<i))
            on.pb(i);
        else
            off.pb(i);
    }

    for(auto i:off)
    {
        ll c=0;
        for(auto j:on)
        {
            c+=arr[i][j];
        }
        for(auto j:off)
        {
            c-=arr[i][j];
        }
        ans=min(ans,c*cnt+dps(mask|(1<<i)));
    }

    return dp[mask]=ans;
}
void solve()
{
    cin>>n>>m;
    cin>>s;
    full=(1<<m)-1;
    rep(i,1,n)
    {
        if(s[i-1]==s[i])
            continue;
        arr[s[i-1]-'a'][s[i]-'a']++;
        arr[s[i]-'a'][s[i-1]-'a']++;
    }
    rep(i,0,20)
    {
        lol[(1<<i)]=i;
    }
    // rep(i,0,3)
    // {
    //     rep(j,0,3)
    //     {
    //         cout<<arr[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    memset(dp,-1,sizeof(dp));
    cout<<dps(0)<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807ll
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define N  100005

ll n,m;
string s;
ll arr[20][20];
ll dp[(1<<20)];
ll full;
unordered_map<ll,ll>lol;
ll dps(ll mask)
{
    if(dp[mask]!=-1)
        return dp[mask];
    ll ans=hell;
    ll rem=full^mask;
    if(rem==0)
        return 0;
    ll cnt=__builtin_popcount(mask)+1;
    ll x=rem;
    while(x!=0)
    {
        ll i=lol[(x&-x)];
            ll res=0;
            rep(j,0,m)
            {
                if(i!=j)
                {
                    if(rem&(1<<j))
                    {
                        res-=arr[j][i]*cnt;
                    }
                    else
                        res+=arr[j][i]*cnt;
                }
            }
            ans=min(ans,res+dps(mask|(1<<i)));
        x-=(x&-x);
    }
    return dp[mask]=ans;
}
void solve()
{
    cin>>n>>m;
    cin>>s;
    full=(1<<m)-1;
    rep(i,1,n)
    {
        arr[s[i-1]-'a'][s[i]-'a']++;
        arr[s[i]-'a'][s[i-1]-'a']++;
    }
    rep(i,0,20)
    {
        lol[(1<<i)]=i;
    }
    // rep(i,0,3)
    // {
    //     rep(j,0,3)
    //     {
    //         cout<<arr[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    memset(dp,-1,sizeof(dp));
    cout<<dps(0)<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll          int
#define pb          push_back
#define INF         9223372036854775807ll
#define    endl        '\n'
#define pii         pair<ll ,ll >
#define vi          vector<ll >
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define N  100005

ll n,m;
string s;
ll arr[20][20];
ll dp[(1<<20)];
ll full;
ll dps(ll mask)
{
    if(mask==full)
        return 0;
    if(dp[mask]!=-1)
        return dp[mask];
    ll ans=hell;
    vi off,on;
    rep(i,0,m)
    {
        if(mask&(1<<i))
            on.pb(i);
        else
            off.pb(i);
    }

    for(auto i:off)
    {
        ll c=0;
        for(auto j:on)
        {
            c+=arr[i][j];
        }
        for(auto j:off)
        {
            c-=arr[i][j];
        }
        ans=min(ans,c*sz(on)+dps(mask|(1<<i)));
    }

    return dp[mask]=ans;
}
void solve()
{
    cin>>n>>m;
    cin>>s;
    full=(1<<m)-1;
    rep(i,1,n)
    {
        if(s[i-1]==s[i])
            continue;
        arr[s[i-1]-'a'][s[i]-'a']++;
        arr[s[i]-'a'][s[i-1]-'a']++;
    }
    memset(dp,-1,sizeof(dp));
    cout<<dps(0)<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807ll
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define N  100005

ll n,m;
string s;
ll arr[20][20];
ll dp[(1<<20)];
ll full;
ll dps(ll mask)
{
    if(dp[mask]!=-1)
        return dp[mask];
    ll ans=hell;
    ll rem=full^mask;
    if(rem==0)
        return 0;
    ll cnt=__builtin_popcount(mask)+1;
    rep(i,0,m)
    {
        if(rem&(1<<i))
        {
            ll res=0;
            rep(j,0,m)
            {
                if(i!=j)
                {
                    if(rem&(1<<j))
                    {
                        res-=arr[j][i]*cnt;
                    }
                    else
                        res+=arr[j][i]*cnt;
                }
            }
            ans=min(ans,res+dps(mask|(1<<i)));
        }
    }
    return dp[mask]=ans;
}
void solve()
{
    cin>>n>>m;
    cin>>s;
    full=(1<<m)-1;
    rep(i,1,n)
    {
        arr[s[i-1]-'a'][s[i]-'a']++;
        arr[s[i]-'a'][s[i-1]-'a']++;
    }
    // rep(i,0,3)
    // {
    //     rep(j,0,3)
    //     {
    //         cout<<arr[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    memset(dp,-1,sizeof(dp));
    cout<<dps(0)<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
#define int long long int
#define sb(x) __builtin_popcount(x)
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
int dp[1 << 20];
int f[26][26], p[20];
string s;

int32_t main()
{
    IOS;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 20; i++)
    {
        p[i] = (1 << i);
    }
    cin >> s;

    for (int i = 1; i < s.size(); i++)
        f[s[i] - 'a'][s[i - 1] - 'a']++;

    dp[0] = 0;
    int tmp, ans, l, r, x, j;
    for (int i = 1; i < (1 << m); i++)
    {
        ans = 1e18;
        for (j = 0; j < m; j++)
        {
            if (i & p[j])
            {
                tmp = dp[i ^ p[j]];
                l = 0, r = 0;
                for (x = 0; x < m; x++)
                {
                    if (x == j)
                        continue;
                    if (i & p[x])
                        l += f[j][x] + f[x][j];
                    else
                        r += f[j][x] + f[x][j];
                }
                ans = min(ans, tmp + (l - r) * sb(i));
            }
        }
        dp[i] = ans;
    }
    cout << dp[(1 << m) - 1];
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
#define int long long int
#define sb(x) __builtin_popcount(x)

int32_t main()
{
    int n, m;
    cin >> n >> m;
    int p[20];
    for (int i = 0; i < 20; i++)
    {
        p[i] = (1 << i);
    }
    string s;
    cin >> s;
    int f[26][26];
    memset(f, 0, sizeof f);

    for (int i = 1; i < s.size(); i++)
    {
        f[s[i] - 'a'][s[i - 1] - 'a']++;
    }

    int dp[(1 << m)] = {};
    dp[0] = 0;

    for (int i = 1; i < (1 << m); i++)
    {

        int ans = 1e18;
        for (int j = 0; j < m; j++)
        {
            if (i & p[j])
            {
                int tmp = dp[i ^ p[j]];
                int l = 0, r = 0;
                for (int x = 0; x < m; x++)
                {
                    if (x == j)
                        continue;
                    if (i & p[x])
                        l += f[j][x] + f[x][j];
                    else
                        r += f[j][x] + f[x][j];
                }
                ans = min(ans, tmp + (l - r) * sb(i));
            }
        }
        dp[i] = ans;
    }
    cout << dp[(1 << m) - 1];
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
#define int long long int
#define sb(x) __builtin_popcount(x)
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int32_t main()
{
    IOS;
    int n, m;
    cin >> n >> m;
    int p[20];
    for (int i = 0; i < 20; i++)
    {
        p[i] = (1 << i);
    }
    string s;
    cin >> s;
    int f[26][26];
    memset(f, 0, sizeof f);

    for (int i = 1; i < s.size(); i++)
        f[s[i] - 'a'][s[i - 1] - 'a']++;

    int dp[(1 << m)] = {};
    dp[0] = 0;

    for (int i = 1; i < (1 << m); i++)
    {
        int ans = 1e18;
        for (int j = 0; j < m; j++)
        {
            if (i & p[j])
            {
                int tmp = dp[i ^ p[j]];
                int l = 0, r = 0;
                for (int x = 0; x < m; x++)
                {
                    if (x == j)
                        continue;
                    if (i & p[x])
                        l += f[j][x] + f[x][j];
                    else
                        r += f[j][x] + f[x][j];
                }
                ans = min(ans, tmp + (l - r) * sb(i));
            }
        }
        dp[i] = ans;
    }
    cout << dp[(1 << m) - 1];
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
// #define int long long int
#define sb(x) __builtin_popcount(x)
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
int dp[1 << 20];
int f[26][26], p[20];
string s;

int32_t main()
{
    IOS;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 20; i++)
    {
        p[i] = (1 << i);
    }
    cin >> s;

    for (int i = 1; i < s.size(); i++)
        f[s[i - 1] - 'a'][s[i] - 'a']++;

    dp[0] = 0;
    int tmp, ans, l, r, x, j;
    for (int i = 1; i < (1 << m); i++)
    {
        ans = 1e18;
        for (j = 0; j < m; j++)
        {
            if (i & p[j])
            {
                tmp = dp[i ^ p[j]];
                l = 0, r = 0;
                for (x = 0; x < m; x++)
                {
                    if (x == j)
                        continue;
                    if (i & p[x])
                        l += f[j][x] + f[x][j];
                    else
                        r += f[j][x] + f[x][j];
                }
                ans = min(ans, tmp + (l - r) * sb(i));
            }
        }
        dp[i] = ans;
    }
    cout << dp[(1 << m) - 1];
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
#define int long long int
#define sb(x) __builtin_popcount(x)
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int32_t main()
{
    IOS;
    int n, m;
    cin >> n >> m;
    int p[20];
    for (int i = 0; i < 20; i++)
    {
        p[i] = (1 << i);
    }
    string s;
    cin >> s;
    int f[26][26];
    memset(f, 0, sizeof f);

    for (int i = 1; i < s.size(); i++)
        f[s[i] - 'a'][s[i - 1] - 'a']++;

    int dp[(1 << m)];
    dp[0] = 0;
    int tmp, ans, l, r, x, j;
    for (int i = 1; i < (1 << m); i++)
    {
        ans = 1e18;
        for (j = 0; j < m; j++)
        {
            if (i & p[j])
            {
                tmp = dp[i ^ p[j]];
                l = 0, r = 0;
                for (x = 0; x < m; x++)
                {
                    if (x == j)
                        continue;
                    if (i & p[x])
                        l += f[j][x] + f[x][j];
                    else
                        r += f[j][x] + f[x][j];
                }
                ans = min(ans, tmp + (l - r) * sb(i));
            }
        }
        dp[i] = ans;
    }
    cout << dp[(1 << m) - 1];
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")

using namespace std;

#define int long long
#define double long double
#define _ << ' ' <<
#define For(i,z) for(int i=0;i<(z);i++)
#define sqr(a) ((a)*(a))

#define pii pair<int, int>
#define pdd pair<double, double>
#define f first
#define s second

template<typename T> inline void umax(T &a, T b) { a = max(a, b); }
template<typename T> inline void umin(T &a, T b) { a = min(a, b); }

const int N = 1e5+10;
//const int INF = 1e16 + 10;
//const pii NINF = make_pair(INF, INF);
const double EPS = 1e-6;
const int II = 1e9;
const int MOD = 1e9 + 7;

int dp[1<<20];
int cnt[20][20];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;
    string s; cin >> s;
    For (i, n-1) {
        cnt[s[i]-'a'][s[i+1]-'a']++;
        cnt[s[i+1]-'a'][s[i]-'a']++;
    }

    For (i, 1<<m) dp[i] = II;
    For (i, m) dp[1<<i] = 0;

    For (msk, 1<<m) {
        int cur = dp[msk];
        For (i, m)
            if (msk & (1 << i))
                For (j, m)
                    if ((msk & (1 << j)) == 0)
                        cur += cnt[i][j];
        For (j, m)
            if ((msk & (1 << j)) == 0)
                umin(dp[msk|(1<<j)], cur);
    }

    cout << dp[(1<<m)-1];
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")

using namespace std;

#define int int64_t
#define double long double
#define _ << ' ' <<
#define For(i,z) for(int i=0;i<(z);i++)
#define sqr(a) ((a)*(a))

#define pii pair<int, int>
#define pdd pair<double, double>
#define f first
#define s second

template<typename T> inline void umax(T &a, T b) { a = max(a, b); }
template<typename T> inline void umin(T &a, T b) { a = min(a, b); }

const int N = 1e5+10;
//const int INF = 1e16 + 10;
//const pii NINF = make_pair(INF, INF);
const double EPS = 1e-6;
const int II = 1e9;
const int MOD = 1e9 + 7;

int dp[1<<20];
int cnt[20][20];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;
    string s; cin >> s;
    For (i, n-1) {
        cnt[s[i]-'a'][s[i+1]-'a']++;
        cnt[s[i+1]-'a'][s[i]-'a']++;
    }

    For (i, 1<<m) dp[i] = II;
    For (i, m) dp[1<<i] = 0;

    For (msk, 1<<m) {
        int cur = dp[msk];
        For (i, m)
            if (msk & (1 << i))
                For (j, m)
                    if ((msk & (1 << j)) == 0)
                        cur += cnt[i][j];
        For (j, m)
            if ((msk & (1 << j)) == 0)
                umin(dp[msk|(1<<j)], cur);
    }

    cout << dp[(1<<m)-1];
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")

using namespace std;

#define int uint16_t
#define double long double
#define _ << ' ' <<
#define For(i,z) for(int i=0;i<(z);i++)
#define sqr(a) ((a)*(a))

#define pii pair<int, int>
#define pdd pair<double, double>
#define f first
#define s second

template<typename T> inline void umax(T &a, T b) { a = max(a, b); }
template<typename T> inline void umin(T &a, T b) { a = min(a, b); }

const int N = 1e5+10;
//const int INF = 1e16 + 10;
//const pii NINF = make_pair(INF, INF);
const double EPS = 1e-6;
const int II = 1e9;
const int MOD = 1e9 + 7;

int dp[1<<20];
int cnt[20][20];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;
    string s; cin >> s;
    For (i, n-1) {
        cnt[s[i]-'a'][s[i+1]-'a']++;
        cnt[s[i+1]-'a'][s[i]-'a']++;
    }

    For (i, 1<<m) dp[i] = II;
    For (i, m) dp[1<<i] = 0;

    For (msk, 1<<m) {
        int cur = dp[msk];
        For (i, m)
            if (msk & (1 << i))
                For (j, m)
                    if ((msk & (1 << j)) == 0)
                        cur += cnt[i][j];
        For (j, m)
            if ((msk & (1 << j)) == 0)
                umin(dp[msk|(1<<j)], cur);
    }

    cout << dp[(1<<m)-1];
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")

using namespace std;

#define int uint32_t
#define double long double
#define _ << ' ' <<
#define For(i,z) for(int i=0;i<(z);i++)
#define sqr(a) ((a)*(a))

#define pii pair<int, int>
#define pdd pair<double, double>
#define f first
#define s second

template<typename T> inline void umax(T &a, T b) { a = max(a, b); }
template<typename T> inline void umin(T &a, T b) { a = min(a, b); }

const int N = 1e5+10;
//const int INF = 1e16 + 10;
//const pii NINF = make_pair(INF, INF);
const double EPS = 1e-6;
const int II = 1e9;
const int MOD = 1e9 + 7;

int dp[1<<20];
int cnt[20][20];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;
    string s; cin >> s;
    For (i, n-1) {
        cnt[s[i]-'a'][s[i+1]-'a']++;
        cnt[s[i+1]-'a'][s[i]-'a']++;
    }

    For (i, 1<<m) dp[i] = II;
    For (i, m) dp[1<<i] = 0;

    For (msk, 1<<m) {
        int cur = dp[msk];
        For (i, m)
            if (msk & (1 << i))
                For (j, m)
                    if ((msk & (1 << j)) == 0)
                        cur += cnt[i][j];
        For (j, m)
            if ((msk & (1 << j)) == 0)
                umin(dp[msk|(1<<j)], cur);
    }

    cout << dp[(1<<m)-1];
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")

using namespace std;

//#define int long long
#define double long double
#define _ << ' ' <<
#define For(i,z) for(int i=0;i<(z);i++)
#define sqr(a) ((a)*(a))

#define pii pair<int, int>
#define pdd pair<double, double>
#define f first
#define s second

template<typename T> inline void umax(T &a, T b) { a = max(a, b); }
template<typename T> inline void umin(T &a, T b) { a = min(a, b); }

const int N = 1e5+10;
//const int INF = 1e16 + 10;
//const pii NINF = make_pair(INF, INF);
const double EPS = 1e-6;
const int II = 1e9;
const int MOD = 1e9 + 7;

int dp[1<<20];
int cnt[20][20];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;
    string s; cin >> s;
    For (i, n-1) {
        cnt[s[i]-'a'][s[i+1]-'a']++;
        cnt[s[i+1]-'a'][s[i]-'a']++;
    }

    For (i, 1<<m) dp[i] = II;
    For (i, m) dp[1<<i] = 0;

    For (msk, 1<<m) {
        int cur = dp[msk];
        For (i, m)
            if (msk & (1 << i))
                For (j, m)
                    if ((msk & (1 << j)) == 0)
                        cur += cnt[i][j];
        For (j, m)
            if ((msk & (1 << j)) == 0)
                umin(dp[msk|(1<<j)], cur);
    }

    cout << dp[(1<<m)-1];
}


#include<bits/stdc++.h>
#define ll int
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll inf = 1000000000 ;

using namespace std ;
ll dp[1024*1024] ;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif

    ll n ,m ;
    cin >> n >> m ;
    string str ;
    cin >> str ;
    ll cnt[m][m] ;
    fo(i , m)
    {
        fo(j , m)
        {
            cnt[i][j] = 0 ;
        }
    }
    fo(i , n-1)
    {
        int a = str[i] - 'a' ;
        int b = str[i+1] - 'a' ;
        if(a != b)
        {
            cnt[a][b]++ ;
            cnt[b][a]++ ;
        }
    }

    fo(i , (1 << m))
    {
        dp[i] = inf;
    }
    dp[0] = 0 ;
    //cout << dp[4] << endl ;

    fo(i , (1 << m))
    {
    	 int pos=(__builtin_popcount(i));
          pos++;
        for(ll j = 0 ; j < m; j++)
        {
            if((i & (1 << j)) == 0)
            {
                ll curr = 0 ;

                for(ll k = 0 ; k < m ; k++)
                {
                    if((i & (1 << k)) == 0) // not in mask
                    {
                        curr -= (cnt[j][k] * pos) ;
                    }
                    else
                        curr += (cnt[j][k] * pos) ;
                }
                //cout << "i = " << i << " j = " << j << " pos = " << pos << " curr = " << curr << endl;
                dp[(i | (1 << j))] = min(dp[(i |(1 << j))] , curr + dp[i]) ;
            }
        }
    }
    //fo(i , (1 << m))
        cout << dp[(1 << m)-1] << ' ';
    cout << endl ;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 1100
#define inf 0x3f3f3f3f
#define eps 1e-8
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

typedef pair<int, int> pii;
typedef long long INT;

int N, M;
double p[NN][NN];
int a[NN];

int main() {
	scanf("%d%d", &N, &M);
	for (int i=0; i<N; i++) scanf("%d", &a[i]);

	for (int i=0; i<N; i++)
		for (int j=i+1; j<N; j++) {
			if (a[i]>a[j]) p[i][j]=1;
		}

	for (int i=0; i<M; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		if (u>v) swap(u, v);
		p[u][v]=0.5;
		for (int j=u+1; j<v; j++) {
			double tu=(p[u][j]+1-p[j][v])/2;
			double tv=(p[j][v]+1-p[u][j])/2;
			p[u][j]=tu; p[j][v]=tv;
		}
	}

	double ans=0;
	for (int i=0; i<N; i++)
		for (int j=i+1; j<N; j++)
			ans+=p[i][j];

	printf("%.10lf\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 1100
#define inf 0x3f3f3f3f
#define mul 1e13
#define eps 1e-8
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

typedef pair<int, int> pii;
typedef long long INT;

int N, M;
long double p[NN][NN];
int a[NN];

int main() {
	scanf("%d%d", &N, &M);
	for (int i=0; i<N; i++) scanf("%d", &a[i]);

	for (int i=0; i<N; i++)
		for (int j=i+1; j<N; j++) {
			if (a[i]>a[j]) p[i][j]=mul;
		}

	for (int i=0; i<M; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		if (u>v) swap(u, v);
		p[u][v]=mul/2;
		for (int j=u+1; j<v; j++) {
			double tu=(p[u][j]+mul-p[j][v])/2;
			double tv=(p[j][v]+mul-p[u][j])/2;
			p[u][j]=tu; p[j][v]=tv;
		}
	}

	long double ans=0;
	for (int i=0; i<N; i++) {
		long double rs=0;
		for (int j=i+1; j<N; j++) {
			rs+=p[i][j];
		}
		ans+=rs;
	}

	printf("%.10lf\n", (double)ans/mul);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
const int maxn=1005;
int n,m,a[maxn];
double dp[maxn][maxn],f[maxn][maxn];
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%d",&a[i]);
	rep(i,1,n)rep(j,1,n)dp[i][j]=a[i]>a[j];
	rep(i,1,m){
		int x,y;scanf("%d%d",&x,&y);
		rep(z,1,n){
			if(z!=x&&z!=y){
				f[x][z]=0.5*(dp[x][z]+dp[y][z]);
				f[y][z]=0.5*(dp[x][z]+dp[y][z]);
			}else if(z==x)f[y][x]=0.5*(dp[x][y]+dp[y][x]);
			else f[x][y]=0.5*(dp[x][y]+dp[y][x]);
			f[z][x]=1-f[x][z];
			f[z][y]=1-f[y][z];
		}
		memcpy(dp,f,sizeof f);
	}
	double ans=0;
	rep(i,1,n)rep(j,i+1,n)ans+=dp[i][j];
	printf("%.10f\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
const int maxn=1005;
int n,m,a[maxn];
double dp[maxn][maxn],f[maxn][maxn];
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%d",&a[i]);
	rep(i,1,n)rep(j,1,n)dp[i][j]=a[i]>a[j];
	rep(i,1,m){
		int x,y;scanf("%d%d",&x,&y);
		rep(z,1,n){
			f[x][z]=dp[x][z];
			f[y][z]=dp[y][z];
		}
		rep(z,1,n){
			if(z!=x&&z!=y)dp[x][z]=dp[y][z]=0.5*(f[x][z]+f[y][z]);
			else dp[y][x]=dp[x][y]=0.5*(f[x][y]+f[y][x]);
			dp[z][x]=1-dp[x][z];
			dp[z][y]=1-dp[y][z];
		}
	}
	double ans=0;
	rep(i,1,n)rep(j,i+1,n)ans+=dp[i][j];
	printf("%.10f\n",ans);
	return 0;
}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

typedef long long LL;
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)

int n, m;
double p[1010][1010];
double sum[1010];
double v[1010];
double par[1010][1010];

double get(int x) {
    double y = 0.0;
    for(;x<=n; x+=x&-x) y += sum[x];
    return y;
}

double update(int x, double y) {
    for(;x>=1; x-=x&-x) sum[x] += y;
}

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin>>n>>m;

    for (int i=0; i<n; i++) {

        int k;
        cin>>k;

        v[i] = k-1;

    }

    for (int i=0; i<n; i++) for (int j=0; j<n; j++) if (v[i]>v[j]) p[i][j] = 1.0;

    for (int i=0; i<m; i++) {

        int a, b;
        cin>>a>>b;
        a--; b--;

        for (int k=0; k<n; k++) if (k!=a && k!=b) {
            double tmp = p[k][a]*0.5 + p[k][b]*0.5;
            p[k][a] = tmp;
            p[k][b] = tmp;
            p[a][k] = 1-tmp;
            p[b][k] = 1-tmp;
        }

        p[a][b] = 0.5;
        p[b][a] = 0.5;

    }

    double res = 0;

    for (int i=0; i<n; i++) for (int j=i+1; j<n; j++) res += p[i][j];

    printf("%.12f", res);

    return 0;

}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

typedef long long LL;
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)

int n, m;
double p[1010][1010];
double sum[1010];
double v[1010];
double par[1010][1010];

double get(int x) {
    double y = 0.0;
    for(;x<=n; x+=x&-x) y += sum[x];
    return y;
}

double update(int x, double y) {
    for(;x>=1; x-=x&-x) sum[x] += y;
}

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin>>n>>m;

    for (int i=0; i<n; i++) {

        int k;
        cin>>k;
        p[i][k-1] = 1.0;

    }

    for (int i=0; i<m; i++) {

        int a, b;
        cin>>a>>b;
        a--; b--;

        for (int j=0; j<n; j++) v[j] = p[a][j];

        for (int j=0; j<n; j++) {

            p[a][j] = 0.5*p[a][j] + 0.5*p[b][j];

        }

        for (int j=0; j<n; j++) {

            p[b][j] = 0.5*v[j] + 0.5*p[b][j];

        }

    }

    double res = 0.0;

    for (int i=0; i<n; i++) {

        par[i][n-1] = p[i][n-1];

        for (int j=n-2; j>=0; j--) par[i][j] = par[i][j+1] + p[i][j];

        for (int j=0; j<n-1; j++) {
            if (p[i][j] < 1.0) par[i][j] = par[i][j+1]/(1.0 - p[i][j]);
        }

    }

    for (int j=0; j<n; j++) {

        for (int i=1; i<n; i++) par[i][j] += par[i-1][j];

    }

    for (int i=0; i<n; i++) {

        for (int j=0; j<n-1; j++) {

            double tmp = 0;

            if (i) tmp += par[i-1][j];

            res += tmp*p[i][j];
            //else res += get(j+2)*p[i][j];

        }

    }

    printf("%.12f", res);

    return 0;

}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <climits>
#include <numeric>
#include <vector>
using namespace std;

const int MAX_N = 1000 + 10;
int n, m;
int a[MAX_N], b[MAX_N];
int p[MAX_N];

double dp[MAX_N][MAX_N];
double tmp[MAX_N][MAX_N];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> a[i] >> b[i];
		--a[i], --b[i];
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			dp[i][j] = 1;
		}
	}

	for (int i = m - 1; i >= 0; --i) {
		int a = ::a[i], b = ::b[i];
		//(a,j)
		for (int j = 0; j < n; ++j) {
			tmp[a][j] = dp[a][j] / 2;
			if ((a < j) == (b < j))
				tmp[a][j] += dp[b][j] / 2;
			else
				tmp[a][j] += (1 - dp[b][j]) / 2;
			tmp[j][a] = tmp[a][j];
		}
		//(b,j)
		for (int j = 0; j < n; ++j) {
			tmp[b][j] = dp[b][j] / 2;
			if ((a < j) == (b < j))
				tmp[b][j] += dp[a][j] / 2;
			else
				tmp[b][j] += (1 - dp[a][j]) / 2;
			tmp[j][b] = tmp[b][j];
		}
		tmp[a][b] = dp[a][b] / 2 + (1 - dp[b][a]) / 2;
		for (int j = 0; j < n; ++j) {
			dp[a][j] = dp[j][a] = tmp[a][j];
			dp[b][j] = dp[j][b] = tmp[b][j];
		}
	}

	double ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < i; ++j) {
			if (p[j] < p[i])
				ans += 1 - dp[j][i];
			else
				ans += 1 - dp[j][i];
		}
	}
	printf("%0.10lf\n", ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <climits>
#include <numeric>
#include <vector>
using namespace std;

const int MAX_N = 1000 + 10;
int n, m;
int a[MAX_N], b[MAX_N];
int p[MAX_N];

double dp[MAX_N][MAX_N];
double tmp[MAX_N][MAX_N];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> a[i] >> b[i];
		--a[i], --b[i];
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			dp[i][j] = 1;
		}
	}

	for (int i = m - 1; i >= 0; --i) {
		int a = ::a[i], b = ::b[i];
		//(a,j)
		for (int j = 0; j < n; ++j) {
			tmp[a][j] = dp[a][j] / 2;
			if ((a < j) == (b < j))
				tmp[a][j] += dp[b][j] / 2;
			else
				tmp[a][j] += (1 - dp[b][j]) / 2;
			tmp[j][a] = tmp[a][j];
		}
		//(b,j)
		for (int j = 0; j < n; ++j) {
			tmp[b][j] = dp[b][j] / 2;
			if ((a < j) == (b < j))
				tmp[b][j] += dp[a][j] / 2;
			else
				tmp[b][j] += (1 - dp[a][j]) / 2;
			tmp[j][b] = tmp[b][j];
		}
		tmp[a][b] = dp[a][b] / 2 + (1 - dp[b][a]) / 2;
		for (int j = 0; j < n; ++j) {
			dp[a][j] = dp[j][a] = tmp[a][j];
			dp[b][j] = dp[j][b] = tmp[b][j];
		}
	}

	double ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < i; ++j) {
			if (p[j] < p[i])
				ans += 1 - dp[j][i];
			else
				ans += dp[j][i];
		}
	}
	printf("%0.10lf\n", ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <climits>
#include <numeric>
#include <vector>
using namespace std;

const int MAX_N = 1000 + 10;
int n, m;
int a[MAX_N], b[MAX_N];
int p[MAX_N];

double dp[MAX_N][MAX_N];
double tmp[MAX_N][MAX_N];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> a[i] >> b[i];
		--a[i], --b[i];
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			dp[i][j] = 1;
		}
	}

	for (int i = m - 1; i >= 0; --i) {
		int a = ::a[i], b = ::b[i];
		//(a,j)
		for (int j = 0; j < n; ++j) {
			tmp[a][j] = dp[a][j] / 2;
			if ((a < j) == (b < j))
				tmp[a][j] += dp[b][j] / 2;
			else
				tmp[a][j] += (1 - dp[b][j]) / 2;
			tmp[j][a] = tmp[a][j];
		}
		//(b,j)
		for (int j = 0; j < n; ++j) {
			tmp[b][j] = dp[b][j] / 2;
			if ((a < j) == (b < j))
				tmp[b][j] += dp[a][j] / 2;
			else
				tmp[b][j] += (1 - dp[a][j]) / 2;
			tmp[j][b] = tmp[b][j];
		}
		tmp[a][b] = tmp[b][a] = dp[a][b] / 2 + (1 - dp[b][a]) / 2;
		for (int j = 0; j < n; ++j) {
			dp[a][j] = dp[j][a] = tmp[a][j];
			dp[b][j] = dp[j][b] = tmp[b][j];
		}
	}

	double ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < i; ++j) {
			if (p[j] < p[i])
				ans += 1 - dp[j][i];
			else
				ans += dp[j][i];
		}
	}
	printf("%0.10lf\n", ans);
	return 0;
}


#include <cstdio>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef pair<ll, ll> lll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1e3 + 7;
const int M = 1000;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int a[N];
int n, q;
double dp[N][N];

int main(){
    //freopen("in.txt", "r", stdin);
    cin >> n >> q;
    rep(i, 1, n + 1) cin >> a[i];

    rep(i, 1, n + 1)
        rep(j, i + 1, n + 1)
            if (a[i] < a[j]) dp[i][j] = 0;
                else dp[i][j] = 1.0;

    while (q-- > 0){
        int u, v;
        scanf("%d%d", &u, &v);
        if (u > v) swap(u, v);
        rep(i, 1, u){
            dp[i][v] = dp[i][u] = dp[i][u] / 2 + dp[i][v] / 2;
        }
        rep(i, u + 1, v){
            double tmp = dp[i][v];
            dp[i][v] = (1 - dp[u][i]) / 2 + dp[i][v] / 2;
            dp[u][i] = 0.5 * dp[u][i] + 0.5 * (1 - tmp);
        }

        rep(i, v + 1, n + 1){
            dp[v][i] = dp[u][i] = (dp[u][i] + dp[v][i]) / 2;
        }
        dp[u][v] = 0.5;
    }

    double ans = 0;
    rep(i, 1, n + 1){
        rep(j, i + 1, n + 1){
            ans += dp[i][j];
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    printf("%.9lf", ans);

}


#include <cstdio>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef pair<ll, ll> lll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1e3 + 7;
const int M = 1000;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int a[N];
int n, q;
double dp[N][N];

int main(){
    //freopen("in.txt", "r", stdin);
    cin >> n >> q;
    rep(i, 1, n + 1) cin >> a[i];

    rep(i, 1, n + 1)
        rep(j, i + 1, n + 1)
            if (a[i] < a[j]) dp[i][j] = 0;
                else dp[i][j] = 1.0;

    while (q-- > 0){
        int u, v;
        scanf("%d%d", &u, &v);
        rep(i, 1, u){
            dp[i][v] = dp[i][u] = dp[i][u] / 2 + dp[i][v] / 2;
        }
        rep(i, u + 1, v){
            double tmp = dp[i][v];
            dp[i][v] = (1 - dp[u][i]) / 2 + dp[i][v] / 2;
            dp[u][i] = 0.5 * dp[u][i] + 0.5 * (1 - tmp);
        }
        dp[u][v] = 0.5;
    }

    double ans = 0;
    rep(i, 1, n + 1){
        rep(j, i + 1, n + 1){
            ans += dp[i][j];
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    printf("%.9lf", ans);

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-9

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 1011

DO dp[NN][NN];

int a[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, m;

	cin >> n >> m;

	for(int i=1; i<=n; i++) gn(a[i]);

	for(int i=1; i<=n; i++) {

		for(int j=i+1; j<=n; j++) {

			dp[i][j] = a[i] > a[j];

		}

	}

	while(m--) {

		int u, v; gn(u, v);

		if(u > v) swap(u, v);

		for(int i=1; i<u; i++) {

			dp[i][u] = dp[i][v] = (dp[i][u] + dp[i][v])/2;

		}

		for(int i=u+1; i<v; i++) {

			DO tmp=dp[u][i];

			dp[u][i] = (dp[u][i] + 1 - dp[i][v]) / 2;

			dp[i][v] = (dp[i][v] + 1 - tmp) / 2;

		}

		for(int i=v+1; i<=n; i++) dp[u][i] = dp[v][i] = (dp[u][i] + dp[v][i]) / 2;

		dp[u][v] =0.5;

	}

	DO ans=0;

	for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++) ans += dp[i][j];

	cout << ans << endl;

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define x first

#define y second

using namespace std;

typedef long long INT;

typedef double DO;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 1010

DO dp[NN][NN];

int p[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n,m;

	scanf("%d%d",&n,&m);

	for(int i=1;i<=n;i++) scanf("%d",&p[i]);

	for(int i=1;i<=n-1;i++){

		for(int j=i+1;j<=n;j++){

			if(p[i]>p[j]) dp[i][j]=1.0;

		}

	}

	while(m--){

		int id, jd;

		scanf("%d%d",&id,&jd);

		if(id>jd) swap(id,jd);

		dp[id][jd]=0.5;

		for(int i=1;i<=id-1;i++){

			dp[i][id]=dp[i][jd]=0.5*dp[i][id]+0.5*dp[i][jd];

		}

		for(int i=id+1;i<jd;i++){

			DO tmp=0.5*dp[id][i]+0.5*(1-dp[i][jd]);

			dp[i][jd]=0.5*dp[i][jd]+0.5*(1-dp[id][i]);

			dp[id][i]=tmp;

		}

		for(int i=jd+1;i<=n;i++){

			dp[jd][i]=dp[id][i]=0.5*dp[jd][i]+0.5*dp[id][i];

		}

	}

	DO ans=0;

	for(int i=1;i<n;i++){

		for(int j=i+1;j<=n;j++) ans+=dp[i][j];

	}

	printf("%.6lf",ans);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef long double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 1010

DO dp[NN][NN];

int a[NN];

int main() {

	int n, m, u, v;

	scanf("%d%d", &n, &m);

	for (int i=1; i<=n; i++) scanf("%d", a+i);

	for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++) dp[i][j]=a[i]>a[j];

	while (m--) {

		scanf("%d%d", &u, &v);

		if (u>v) swap(u, v);

		dp[u][v]=0.5;

		for (int i=1; i<u; i++) dp[i][u]=dp[i][v]=(dp[i][u]+dp[i][v])/2;

		for (int i=v+1; i<=n; i++) dp[u][i]=dp[v][i]=(dp[u][i]+dp[v][i])/2;

		for (int i=u+1; i<v; i++) {

			DO t1=dp[u][i]*0.5+(1-dp[i][v])*0.5;

			DO t2=dp[i][v]*0.5+(1-dp[u][i])*0.5;

			dp[u][i]=t1, dp[i][v]=t2;

		}

	}

	DO ans=0;

	for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++) ans+=dp[i][j];

	printf("%.10lf\n", (double)ans);

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2, x3), gn(x4);}

template <class T1, class T2, class T3, class T4, class T5> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {gn(x1, x2, x3, x4), gn(x5);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

template <class T1, class T2, class T3, class T4, class T5> inline void print(T1 x1, T2 x2, T3 x3, T4 x4, T5 x5) {printsp(x1), printsp(x2), printsp(x3), printsp(x4), println(x5);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 1100

int a[NN];

DO dp[NN][NN];

int main(){

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n,m;

	gn(n,m);

	for(int i=1;i<=n;i++) gn(a[i]);

	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){

		if(i==j) continue;

		if(a[i]>a[j]) dp[i][j]=1;

	}

	while(m--){

		int u,v;

		gn(u,v);

		if(u>v) swap(u,v);

		dp[v][u]=dp[u][v]=(dp[u][v]+dp[v][u])/2;

		for(int i=1;i<=n;i++){

			if(u==i || v==i) continue;

			DO x=dp[v][i]+dp[u][i];

			DO y=dp[i][v]+dp[i][u];

			dp[i][v]=dp[i][u]=y/2;

			dp[u][i]=dp[v][i]=x/2;

		}

	}

	DO ans=0;

	for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) {

		ans+=dp[i][j];

	}

	printf("%.6lf",ans);

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define hmod 911382323

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define LEN(a) (a.length())

#define x first

#define y second

#define ls (u<<1)

#define rs (ls + 1)

#define mid (st + ed >> 1)

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define rands(n) (rand()%n+1)

#define rand0(n) (rands(n)-1)

#define Rands(n) ((INT)rand()*rand()%n+1)

#define Rand0(n) (Rands(n)-1)

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define shit(a) (1 << (a))

#define all(a) ((a).begin(), (a).end())

#define rev(a) (power(a, mod-2, mod))

#define add_edge(u, v) {nxt[E]=head[u];to[E]=v;head[u]=E++;}

#define init_edge(n) {memset(head, -1, sizeof head);E=0;}

#define input_tree {int n;cin>>n;init_edge(n); for(int i=0, u, v; i<n-1; i++) {gn(u); gn(v); add_edge(u,v); add_edge(v,u);}}

#define ADD(u, v) {u+=v;u%=mod;}

using namespace std;

typedef long long INT;

typedef unsigned long long UINT;

typedef unsigned int uint;

typedef complex<double> Complex;

typedef double DO;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef pair<int, pii> pip;

typedef pair<DO, DO> pdd;

typedef pair<int, DO> pid;

typedef pair<DO, int> pdi;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

inline uint myrand(int n) {

	uint u = rand()%n;

	int c = rand()%10;

	u ^= u << c;

	u^=(u<<7)&263692864;

	u^=(u<<15)&402273075;

	u%=n;

	return u;

}

#define NN 1011

DO p[NN][NN];

int a[NN];

int n, m;

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	cin >> n >> m;

	for(int i=1; i<=n; i++) gn(a[i]);

	for(int i=1; i<=n; i++) {

		for(int j=i+1; j<=n; j++) {

			if(a[i] > a[j]) p[i][j] = 1;

		}

	}

	int u, v;

	DO tmp;

	while(m--) {

		gn(u, v);

		if(u > v) swap(u, v);

		for(int i=1; i<u; i++) p[i][u] = p[i][v] = (p[i][u] + p[i][v])/2;

		for(int i=u+1; i<v; i++) {

			tmp = (p[i][v] + 1 - p[u][i])/2;

			p[u][i] = (p[u][i] + 1 - p[i][v])/2;

			p[i][v] = tmp;

		}

		for(int i=v+1; i<=n; i++) p[u][i] = p[v][i] = (p[u][i] + p[v][i])/2;

		p[u][v]=0.5;

	}

	DO ans=0;

	for(int i=1; i<=n; i++) {

		for(int j=i+1; j<=n; j++) ans+=p[i][j];

	}

	printf("%.9lf\n", ans);

#ifndef ONLINE_JUDGE

	cerr<<"The running time is : " << (DO)(clock()-_time) / CLOCKS_PER_SEC<<endl;

#endif

	return 0;

}