#include <bits/stdc++.h>
using namespace std;
char S[200010];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", S);
  int l = -1;
  int best = 2e9;
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    if (S[i] == 'L') {
      if (l != -1) {
        best = min(best, (p - l) / 2);
      }
    } else {
      l = p;
    }
  }
  if (best == 2e9)
    printf("-1\n");
  else
    printf("%d\n", best);
}
