#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, x;
  string s;
  cin >> n >> s;
  vector<int> left, right;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (s[i] == 'L')
      left.push_back(x / 2);
    else
      right.push_back(x / 2);
  }
  sort(left.begin(), left.end());
  sort(right.begin(), right.end());
  int ans = INT_MAX;
  bool collide = false;
  for (int i = 0; i < right.size(); i++) {
    vector<int>::iterator f = upper_bound(left.begin(), left.end(), right[i]);
    if (f == left.end())
      continue;
    else {
      collide = true;
      ans = min(*f - right[i], ans);
    }
  }
  if (collide)
    cout << ans;
  else
    cout << -1;
  return 0;
}
