#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<cassert>
#include<functional>
typedef long long ll;

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int n;
	int x;
	std::string s;

	std::cin >> n >> x >> s;

	for (int i = 0; i < n; i++){
		if (s.at(i) == 'o'){
			x += 1;
		}
		else{
			x -= 1;
			if (x < 0){
				x = 0;
			}
		}
	}

	std::cout << x << '\n';

	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

int debug = 0;

const int N = 2010, inf = 1e9;
int n, m, ans, dp[N][N];
vector <int> g[26][N];

main() {
    cin >> n >> m;
    rep(i, 1, n + 1) {
        rep(j, 1, n + 1) {
            if (i == j) {
                dp[i][j] = 0;
            } else {
                dp[i][j] = inf;
            }
        }
    }
    rep(i, 0, m) {
        int a, b, c; char cc;
        cin >> a >> b >> cc;
        c = cc - 'a';
        if (debug) {
            cerr << " edge: " <<  a << ' ' << b << ' ' << cc << endl;
        }
        g[c][a].push_back(b);
        g[c][b].push_back(a);
        if (a != b) dp[a][b] = dp[b][a] = 1;
    }
    set <array <int, 3>> d;
    rep(i, 1, n + 1) rep(j, i, n + 1) {
        d.insert({dp[i][j], i, j});
    }
    while (!d.empty()) {
        auto cur = *d.begin();
        d.erase(cur);
        int w = cur[0], a = cur[1], b = cur[2];
        if (debug) cerr << w << ' ' << a << ' ' << b << '\n';
        assert(a <= b);
        if (w == inf) break;
        rep(c, 0, 26) {
            for (int u : g[c][a]) for (int v : g[c][b]) {
                int uu = u, vv = v;
                if (uu > vv) swap(uu, vv);
                if (dp[uu][vv] > w + 2) {
                    d.erase({dp[uu][vv], uu, vv});
                    dp[uu][vv] = w + 2;
                    d.insert({dp[uu][vv], uu, vv});
                }
            }
        }
    }
    if (dp[1][n] == inf) {
        ans = -1;
    } else {
        ans = dp[1][n];
    }
    cout << ans << '\n';
}