#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  int d, l;
} a[200005];
int ans = 1000000000;
char ch[200005];
int main() {
  scanf("%d", &n);
  scanf("%s", ch + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].l);
    if (ch[i] == 'L')
      a[i].d = -1;
    else
      a[i].d = 1;
  }
  for (int i = 1; i < n; i++) {
    if ((a[i].d == 1) && (a[i + 1].d == -1))
      ans = min(ans, (a[i + 1].l - a[i].l) / 2);
  }
  if (ans == 1000000000) ans = -1;
  printf("%d", ans);
}
