#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n], x1, mi = 10000000000, k = 0;
  char c[n];
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (c[i] == 'L' && k == 1) {
      if (a[i] - x1 < mi) mi = a[i] - x1;
    } else if (c[i] == 'R') {
      k = 1;
      x1 = a[i];
    }
  }
  if (mi != 10000000000)
    cout << mi / 2;
  else
    cout << -1;
  return 0;
}
