#include <bits/stdc++.h>
using namespace std;
struct node {
  char fx;
  long long zb;
} point[200005];
long long jl[200005];
long long jl1[200005];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    getchar();
    for (int i = 0; i < n; i++) scanf("%c", &point[i].fx);
    int num = 0, num1 = 0;
    for (int i = 0; i < n; i++) {
      cin >> point[i].zb;
      if (point[i].fx == 'L')
        jl[num++] = point[i].zb;
      else
        jl1[num1++] = point[i].zb;
    }
    if (num == 0 || num1 == 0)
      printf("-1\n");
    else {
      long long mint = 20000000000;
      int now = 0, now1 = 0;
      bool flag = false;
      for (; now1 < num1; now1++) {
        for (;; now++) {
          if (jl[now] > jl1[now1]) {
            mint = min(mint, (jl[now] - jl1[now1]) / 2);
            break;
          }
          if (now == num - 1) {
            flag = true;
            break;
          }
        }
        if (mint == 1 || flag) break;
      }
      if (mint == 20000000000)
        printf("-1\n");
      else
        cout << mint << endl;
    }
  }
  return 0;
}
