#include using namespace std; typedef long long ll; typedef pair PII; const int MM = 1e9 + 7; const double eps = 1e-8; const int MAXN = 2e6 + 10; int n, m; void prework(){ } void read(){ } char s[MAXN]; int f[MAXN]; int gao(int x){ for (int i = 1; i <= n; i++) f[i] = (s[i] == '#'); int st = 0; for (int i = 1; i <= n; i++) if (f[i] == 1){ st = i; break; } int ed = n + 1; for (int i = n; i >= 1; i--) if (f[i] == 1){ ed = i; break; } int ret = 0; if (x > st){ for (x--; x >= st; x--){ ret++; f[x] = 1 - f[x]; //cout << ret << ' ' << x << endl; } x++; } f[n + 1] = 1; f[n + 2] = 0; //cout << "!!!! " << st << ' ' << ed << ' ' << ret << ' ' << x << endl; while(true){ if (f[x] == 0){ ret++; x++; f[x] = 1 - f[x]; //cout << ret << ' ' << x << endl; } else{ if (x == n){ ret += 3; break; } ret++; x++; f[x] = 1 - f[x]; //cout << ret << ' ' << x << endl; ret++; x--; f[x] = 1 - f[x]; //cout << ret << ' ' << x << endl; } if (x >= ed - 1 && f[x] == 0 && (f[x + 1] == 0 || x == n)) break; } //cout << "=========== " << ret << endl; return ret; } void solve(int casi){ // cout << "Case #" << casi << ": "; scanf("%d", &m); scanf("%s", s + 1); n = strlen(s + 1); int ans = gao(m); reverse(s + 1, s + n + 1); ans = min(ans, gao(n + 1 - m)); printf("%d", ans); } void printans(){ } int main(){ // std::ios::sync_with_stdio(false); prework(); int T = 1; // cin>>T; for(int i = 1; i <= T; i++){ read(); solve(i); printans(); } return 0; }