#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int N, K, D[2] = { -1, +1 }; string S; int solve(vi a, int d, int p) { int to = 0; int res = 0; int cnt = 0; for (int i = p; i >= 0 && i < K; i+=d) { if (a[i]) { cnt++; to = i; } } for (int i = p; i != to + d; i += d) { if (a[i]) { if (i == to) { a[i] ^= 1; res += 3; } else { a[i] ^= 1; a[i + d] ^= 1; if (a[i + d])cnt++; else cnt--; i -= d; res += 2; } cnt--; } else { if (i != to) { a[i + d] ^= 1; if (a[i + d])cnt++; else cnt--; res++; } } if (cnt == 0)break; } return res; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> N >> S; K = sz(S); N--; int l = -1, r = -1; rep(i, K) if (S[i] == '#')r = i; for (int i = K - 1; i >= 0; --i)if (S[i] == '#')l = i; int P[] = { l,r }; int ans = INT_MAX; rep(x, 2) { int d = D[x]; int p = P[x]; vi v(K); rep(i, K)v[i] = S[i] == '#' ? 1 : 0; for (int i = N + d; i != p + d; i += d) v[i] ^= 1; smin(ans, solve(v, -d, p) + abs(N-p)); } cout << ans << endl; }