#include <bits/stdc++.h>
using namespace std;
const int maxn = 0x3f3f3f3f;
int dir[200000 + 100];
int pos[200000 + 100];
int main() {
  int n;
  char ch;
  memset(dir, 0, sizeof(dir));
  memset(pos, 0, sizeof(pos));
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    scanf("%c", &ch);
    if (ch == 'L')
      dir[i] = 0;
    else
      dir[i] = 1;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &pos[i]);
  }
  int ans = 0x3f3f3f3f;
  for (int i = 1; i < n; i++) {
    int temp = 0x3f3f3f3f;
    if (dir[i - 1] == 1 && 0 == dir[i]) {
      temp = (pos[i] - pos[i - 1]) / 2;
    }
    ans = min(temp, ans);
  }
  if (ans == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
