#include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const set& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; N--; string S; cin >> S; const int size = S.size(); auto solve1 = [&]() { if (N > 1000) { return INF; } vector need(size); set st; for (int i = 0; i < size; i++) { need[i] = S[i] == '#'; if (need[i]) { st.insert(i); } } int pos = N; bool l = true; int ans = 0; while (not st.empty()) { const int left = *st.cbegin(); const int right = *st.crbegin(); if (l) { for (; pos > left; pos--) { ans++; if (need[pos - 1]) { st.erase(pos - 1); } else { st.insert(pos - 1); } need[pos - 1] = not need[pos - 1]; } } else { for (; pos < right; pos++) { ans++; if (need[pos + 1]) { st.erase(pos + 1); } else { st.insert(pos + 1); } need[pos + 1] = not need[pos + 1]; } } l = not l; } return ans; }; auto solve2 = [&]() { if (N > 1000) { return INF; } vector need(size); set st; for (int i = 0; i < size; i++) { need[i] = S[i] == '#'; if (need[i]) { st.insert(i); } } int pos = N; bool l = false; int ans = 0; while (not st.empty()) { const int left = *st.cbegin(); const int right = *st.crbegin(); if (l) { for (; pos > left; pos--) { ans++; if (need[pos - 1]) { st.erase(pos - 1); } else { st.insert(pos - 1); } need[pos - 1] = not need[pos - 1]; } } else { for (; pos < right; pos++) { ans++; if (need[pos + 1]) { st.erase(pos + 1); } else { st.insert(pos + 1); } need[pos + 1] = not need[pos + 1]; } } l = not l; } return ans; }; auto solve3 = [&]() { vector need(size); set st; for (int i = 0; i < size; i++) { need[i] = S[i] == '#'; if (need[i]) { st.insert(i); } } int pos = N; bool l = true; int ans = 0; int cnt = 0; while (not st.empty() and cnt < 2) { const int left = *st.cbegin(); const int right = *st.crbegin(); if (l) { for (; pos > left; pos--) { ans++; if (need[pos - 1]) { st.erase(pos - 1); } else { st.insert(pos - 1); } need[pos - 1] = not need[pos - 1]; } } else { for (; pos < right; pos++) { ans++; if (need[pos + 1]) { st.erase(pos + 1); } else { st.insert(pos + 1); } need[pos + 1] = not need[pos + 1]; if (need[pos]) { ans += (pos == right - 1 ? 1 : 2); need[pos] = not need[pos]; st.erase(pos); need[pos + 1] = (pos == right - 1 ? need[pos + 1] : not need[pos + 1]); if (need[pos + 1]) { st.insert(pos + 1); } } } } l = not l; cnt++; } return ans; }; auto solve4 = [&]() { vector need(size); set st; for (int i = 0; i < size; i++) { need[i] = S[i] == '#'; if (need[i]) { st.insert(i); } } int pos = N; bool l = false; int ans = 0; int cnt = 0; while (not st.empty() and cnt < 2) { const int left = *st.cbegin(); const int right = *st.crbegin(); if (l) { for (; pos > left; pos--) { ans++; if (need[pos - 1]) { st.erase(pos - 1); } else { st.insert(pos - 1); } need[pos - 1] = not need[pos - 1]; if (need[pos]) { ans += (pos == left + 1 ? 1 : 2); need[pos] = not need[pos]; st.erase(pos); need[pos - 1] = (pos == left + 1 ? need[pos - 1] : not need[pos - 1]); if (pos > left + 1) { st.insert(pos - 1); } } } } else { for (; pos < right; pos++) { ans++; if (need[pos + 1]) { st.erase(pos + 1); } else { st.insert(pos + 1); } need[pos + 1] = not need[pos + 1]; } } l = not l; cnt++; } return ans; }; cout << min({solve1(), solve2(), solve3(), solve4()}) << endl; return 0; // cout << ans << endl; return 0; }