#include <bits/stdc++.h>
using namespace std;
vector<long> R, L;
vector<long>::iterator Rit, Lit;
long a[long(2e5 + 100)];
int main() {
  long n;
  string s;
  scanf("%ld", &n);
  cin >> s;
  long res = 999999999;
  for (long i = 0; i < s.length(); ++i)
    if (s[i] == 'R')
      R.push_back(i + 1);
    else
      L.push_back(i + 1);
  for (long i = 1; i <= n; ++i) scanf("%ld", &a[i]);
  for (long i = 0; i < R.size(); ++i) {
    Lit = lower_bound(L.begin(), L.end(), R[i]);
    if (Lit == L.end()) continue;
    long x = *Lit;
    res = min(res, (a[*Lit] - a[R[i]]) / 2);
  }
  if (res != 999999999)
    printf("%ld", res);
  else
    puts("-1");
}
