import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); Deque deq = new ArrayDeque<>(); int ans = 0; for (char c : sc.next().toCharArray()) { if (deq.size() == 0) { deq.add(c); } else if (deq.size() == 1) { if (deq.peekLast() != c) { deq.add(c); } } else { if (deq.peekLast() != c) { char x = deq.pollLast(); if (deq.peekLast() == c) { ans++; } else { deq.add(x); deq.add(c); } } } } ans += deq.size(); char first = deq.peekFirst(); while (deq.size() > 0) { char x = deq.poll(); if (x == first) { ans--; } } System.out.println(ans + 1); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }