#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> x, d;
int main() {
  unsigned long long n, l = 200001, r = 200001, tmp;
  string s;
  cin >> n >> s;
  for (long long i = n - 1; i >= 0; i--) {
    if (s[i] == 'L') {
      l = i;
      break;
    }
  }
  for (unsigned long long i = 0; i < n; i++)
    if (s[i] == 'R') {
      r = i;
      break;
    }
  if (l == 200001 || r == 200001) {
    cout << -1;
    return 0;
  }
  for (unsigned long long i = 0; i < n; i++) {
    cin >> tmp;
    x.push_back(tmp);
  }
  if (r > l) {
    cout << -1;
    return 0;
  }
  for (unsigned long long i = 0; i < n - 1; i++) {
    if (s[i] == 'R' && s[i + 1] == 'L') d.push_back(x[i + 1] - x[i]);
  }
  cout << *min_element(d.begin(), d.end()) / 2;
}
