#include <bits/stdc++.h>
using namespace std;
const int eps = 1000000007;
int inf = -1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<char> A(n);
  vector<int> B(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> B[i];
  }
  int min1 = eps;
  for (int i = 0; i < n - 1; i++) {
    if (A[i] == 'R' && A[i + 1] == 'L') {
      min1 = min((B[i + 1] - B[i]) / 2, min1);
    }
  }
  if (min1 != eps) {
    cout << min1;
  } else {
    cout << -1;
  }
  return 0;
}
