#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 1200000;
char s[maxn];
struct {
  int max[maxn << 2], min[maxn << 2], sum[maxn << 2];
  void add(int v, int tl, int tr, int p, int x) {
    if (tl == tr) {
      sum[v] += x;
      min[v] = std::min(0, sum[v]);
      max[v] = std::max(0, sum[v]);
    } else {
      if (p <= ((tl + tr) >> 1))
        add((v << 1), tl, ((tl + tr) >> 1), p, x);
      else
        add(((v << 1) | 1), ((tl + tr) >> 1) + 1, tr, p, x);
      sum[v] = sum[(v << 1)] + sum[((v << 1) | 1)];
      min[v] = std::min(min[(v << 1)], sum[(v << 1)] + min[((v << 1) | 1)]);
      max[v] = std::max(max[(v << 1)], sum[(v << 1)] + max[((v << 1) | 1)]);
    }
  }
} T;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, sum = 0;
  string op;
  cin >> n >> op;
  for (int i = 0, p = 1; i < n; i += 1) {
    if (op[i] == 'L')
      p = max(p - 1, 1);
    else if (op[i] == 'R')
      p += 1;
    else {
      if (s[p] == '(') T.add(1, 1, n, p, -1), sum -= 1;
      if (s[p] == ')') T.add(1, 1, n, p, 1), sum += 1;
      s[p] = op[i];
      if (s[p] == '(') T.add(1, 1, n, p, 1), sum += 1;
      if (s[p] == ')') T.add(1, 1, n, p, -1), sum -= 1;
    }
    if (sum or T.min[1] < 0)
      cout << "-1\n";
    else
      cout << T.max[1] << "\n";
  }
}
