<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$v = preg_replace('/(W+)/','W',$key->A[0]);
$v = preg_replace('/(B+)/','B',$v);
if (chk($v)) {
  printf("%d\n",0);
  exit;
}
//先頭に違う色の石を足してOKになるか調べる
$r1 = min(solv($key->A[0]),solv(strrev($key->A[0])));
printf("%d\n",$r1);
function chk($r) {
  $len = strlen($r);
  $w = 0;
  $b = 0;
  for($i=0;$i<$len;$i++) {
    if ($r[$i]=='W') $w++;
    else $b++;
  }
  if ($b == 0 || $w == 0) return true;
  return false;
}
function solv($v) {
  $f=0;
while(1) {
  $len  = strlen($v);
  if ($v[0]=='W') {
    $new = 'B';
  }
  else {
    $new = 'W';
  }
  for($i=0;$i<$len;$i++) {
    if ($v[$i]==$new) {
      break;
    }
    else {
      $v[$i]=$new;
    }
  }
  $v = $new . $v;
  $f++;
  //同じ色になったか？
  if (chk($v)) break;
}
return $f;
}
