#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char direction[N];
int position[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> direction[i];
  for (int i = 0; i < n; ++i) cin >> position[i];
  int answer = 0x3f3f3f3f;
  for (int rPtr = 0, lPtr = 0; rPtr < n; rPtr++) {
    if (direction[rPtr] == 'L') continue;
    for (; lPtr < n; ++lPtr) {
      if (lPtr <= rPtr) continue;
      if (direction[lPtr] == 'R') continue;
      answer = min(answer, (position[lPtr] - position[rPtr]) / 2);
      break;
    }
  }
  if (answer == 0x3f3f3f3f) answer = -1;
  cout << answer << endl;
}
