#include <bits/stdc++.h>
using namespace std;
int n;
int a[200001];
string s;
long long giay = 1000000000;
int main() {
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; i++) cin >> a[i];
  int i = 0;
  while (s[i] == 'L') i++;
  int r = n - 1;
  while (s[r] == 'R') r--;
  if (i > r) {
    cout << -1;
    return 0;
  } else {
    for (int k = i + 1; k <= r; k++)
      if (s[k] != s[k - 1] && s[k] == 'L') {
        long long tam = (a[k] + a[k - 1]) / 2;
        long long na = a[k] - tam;
        long long nb = tam - a[k - 1];
        long long mn = na;
        if (na > nb) mn = nb;
        if (nb < giay) giay = nb;
      }
    cout << giay;
  }
  return 0;
}
