#include <bits/stdc++.h>
using namespace std;
char str[1010000];
int b[1010000];
int a[1010000];
int bb[1010000];
int main() {
  int n;
  int flag = 1;
  scanf("%d", &n);
  scanf("%s", str);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  int coutt1 = 0;
  for (int i = 0; i <= n - 1; i++) {
    if (str[i] == 'R') {
      coutt1++;
      a[coutt1] = b[i + 1];
    }
  }
  int coutt2 = 0;
  for (int i = 0; i <= n - 1; i++) {
    if (str[i] == 'L') {
      coutt2++;
      bb[coutt2] = b[i + 1];
    }
  }
  int ans = 1000000005;
  int i, j;
  for (i = 1, j = 1; i <= coutt1 && j <= coutt2;) {
    if (a[i] < bb[j]) {
      flag = 0;
      ans = min((bb[j] - a[i]) / 2, ans);
      i++;
    } else {
      j++;
    }
  }
  if (flag)
    printf("-1");
  else
    printf("%d", ans);
}
