#include <bits/stdc++.h>
using namespace std;
struct node {
  int rec;
  int dis;
  int left;
  int right;
} ant[200005];
char st[200005];
bool cmp(node a, node b) { return (a.dis < b.dis); }
int main() {
  int n;
  int a;
  scanf("%d", &n);
  scanf("%s", st);
  int len = strlen(st);
  for (int i = 0; i < len; ++i) {
    if (st[i] == 'L')
      ant[i].rec = 1;
    else
      ant[i].rec = 2;
    scanf("%d", &a);
    ant[i].dis = a;
  }
  sort(ant, ant + n, cmp);
  int right = -1;
  for (int i = 0; i < n; ++i) {
    if (ant[i].rec == 2) right = ant[i].dis;
    ant[i].right = right;
  }
  int left = -1;
  for (int i = n - 1; i >= 0; --i) {
    if (ant[i].rec == 1) left = ant[i].dis;
    ant[i].left = left;
  }
  int Min = 0x3f3f3f3f;
  for (int i = 0; i < n; ++i) {
    if (ant[i].left != -1 && ant[i].right != -1) {
      if ((ant[i].left - ant[i].right) / 2 < Min)
        Min = (ant[i].left - ant[i].right) / 2;
    }
  }
  if (Min == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", Min);
  return 0;
}
