#include <bits/stdc++.h>
char a[200200];
int main() {
  int i, j, n, max = 0, p, ans = 2100000000, ch = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf(" %c", &a[i]);
  for (i = 0; i < n; i++) {
    scanf("%d", &p);
    if (a[i] == 'R') {
      max = p;
      ch = 1;
    } else if (ch == 1)
      ans = (((ans) < ((p - max) / 2)) ? (ans) : ((p - max) / 2));
  }
  if (ans == 2100000000) ans = -1;
  printf("%d\n", ans);
  return 0;
}
