#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>


int main(){
    int N,X; std::cin >> N >> X;
    std::string s;
    std::cin >> s;
    for(const auto& c : s){
        X += (c == 'o' ? 1 : -1);
        X = std::max(0,X);
    }
    std::cout << X << std::endl;
}



#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <=b ; ++i)
#define per(i, b, a) for(int i = b; i >= a; --i)
#define ll long long
#define pb push_back
using namespace std;
inline void rd(int &x){scanf("%d", &x);}
inline void rd(ll &x){scanf("%lld", &x);}
int n, m, k;
const int maxn = 1145;
int par[maxn << 1];
int findroot(int u)
{
    return par[u] == u ? par[u] : (par[u] = findroot(par[u]));
}
void merge(int u, int v)
{
    if(findroot(u) == findroot(v)) return;
    par[findroot(u)] = v;
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> m;
    rep(i, 1, n + m) par[i] = i;
    rep(i, 1, n)
    {
        string s;
        cin >> s;
        rep(j, 1, m) if(s[j - 1] == '#') merge(i, n + j);
    }
    merge(1, n + 1), merge(1, n + m), merge(n, n + 1), merge(n, n + m);
    int ans = 0;
    unordered_set<int> r, c;
    rep(i, 1, n) r.insert(findroot(i));
    rep(j, 1, m) c.insert(findroot(j + n));
    cout << min(r.size(), c.size()) - 1;
}