#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::clog;
using std::cout;
using std::pow;
using std::priority_queue;
using std::stack;
using std::string;
using std::unordered_map;
using std::unordered_set;
using std::vector;
vector<string> &split(const string &s, char delim, vector<string> &elems) {
  std::stringstream ss(s);
  std::string item;
  while (std::getline(ss, item, delim)) {
    elems.push_back(item);
  }
  return elems;
}
vector<string> split(const string &s, char delim) {
  vector<string> elems;
  split(s, delim, elems);
  return elems;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> dir(n);
  string line;
  cin >> line;
  bool possible = false;
  for (int i = 0; i < line.length(); i++) {
    if (line[i] == 'R') {
      dir[i] = 1;
    } else if (line[i] == 'L') {
      dir[i] = -1;
    }
  }
  vector<int> pos(n);
  for (int i = 0; i < n; i++) {
    cin >> pos[i];
  }
  long minDis = LONG_MAX;
  int lastRight = -1;
  for (int i = 0; i < n; i++) {
    if (dir[i] == 1) {
      lastRight = i;
    } else if (dir[i] == -1) {
      if (lastRight != -1) {
        possible = true;
        int dist = pos[i] - pos[lastRight];
        if (dist < minDis) {
          minDis = dist;
        }
      }
    }
  }
  if (possible) {
    cout << minDis / 2 << "\n";
  } else {
    cout << -1 << "\n";
  }
  return 0;
}
