#include <bits/stdc++.h>
using namespace std;
struct my {
  char ch;
  long long v;
};
my ar[200010];
long long br[200010];
int main() {
  long long n;
  while (~scanf("%lld", &n)) {
    getchar();
    long long i = 0, j = 0, x;
    char dir;
    for (j = 1; j <= n; j++) {
      scanf("%c", &dir);
      i++;
      ar[i].ch = dir;
    }
    i = 0;
    for (j = 1; j <= n; j++) {
      scanf("%lld", &x);
      i++;
      ar[i].v = x;
    }
    long long k = 1, cnt = 2147483647;
    for (i = 1; i <= n - 1; i++) {
      if (ar[i].ch == 'R' and ar[i + 1].ch == 'L') {
        cnt = min(cnt, (abs(ar[i].v - ar[i + 1].v)) / 2);
      }
    }
    if (cnt == 2147483647) {
      cnt = -1;
    }
    printf("%lld\n", cnt);
  }
  return 0;
}
