#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, t = -1;
  char c;
  cin >> n;
  vector<char> d;
  vector<int> coord;
  for (int i = 0; i < n; i++) {
    cin >> c;
    d.push_back(c);
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    coord.push_back(x);
  }
  for (int i = 0; i < n - 1; i++) {
    if (d[i] == 'R' && d[i + 1] == 'L') {
      int time = (coord[i + 1] - coord[i]) / 2;
      if (t == -1)
        t = time;
      else
        t = min(t, time);
    }
  }
  cout << t << endl;
}
