#include <bits/stdc++.h>
using namespace std;
int n;
char dir[200005];
int l[200005], r[200005], ll, rl;
int ans = 0x7fffffff;
int main() {
  cin >> n;
  getchar();
  for (int i = 1; i <= n; i++) scanf("%c", &dir[i]);
  for (int i = 1; i <= n; i++)
    if (dir[i] == 'L')
      scanf("%d", &l[++ll]);
    else
      scanf("%d", &r[++rl]);
  if (ll == 0 || rl == 0) {
    puts("-1");
    return 0;
  }
  int nowl = 1, nowr = 1;
  for (nowl = 1; nowl <= ll; nowl++) {
    do {
      nowr++;
    } while (nowr <= rl && r[nowr] < l[nowl]);
    nowr--;
    if (l[nowl] - r[nowr] > 0) ans = min(ans, l[nowl] - r[nowr]);
  }
  if (ans == 0x7fffffff) {
    puts("-1");
    return 0;
  } else
    cout << (ans >> 1) << endl;
  return 0;
}
