#include <bits/stdc++.h>
using namespace std;
int strtoint(const string &x) {
  int r = 0;
  for (int i = 0; i < (int)x.size(); i++) r = r * 10 + (x[i] - '0');
  return r;
}
int getval(string &x) {
  if (x == "?")
    return -1;
  else
    return strtoint(x);
}
const int maxn = 310;
int precycle[maxn], cycle[maxn];
pair<int, int> format[maxn * 4];
int cnum[maxn], tower[maxn];
vector<int> con[maxn * 4];
int match[maxn], match2[maxn];
int used[maxn * 4];
int F;
bool dfs(int v) {
  if (used[v] == F) return 0;
  used[v] = F;
  for (int j : con[v])
    if (match2[j] == -1 || dfs(match2[j])) {
      match2[j] = v;
      return 1;
    }
  return 0;
}
bool ls(int a, int b) {
  int knowna = int(precycle[a] != -1) + int(cycle[a] != -1);
  int knownb = int(precycle[b] != -1) + int(cycle[b] != -1);
  if (knowna != knownb) return knowna > knownb;
  return (precycle[a] == -1 ? (int)1e9 : precycle[a]) <
         (precycle[b] == -1 ? (int)1e9 : precycle[b]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string u, v;
    cin >> u >> v;
    precycle[i] = getval(u);
    cycle[i] = getval(v);
  }
  vector<int> ord(n);
  for (int i = 0; i < n; i++) ord[i] = i;
  sort(ord.begin(), ord.end(), ls);
  for (int fixi = 1; fixi <= n; fixi++) {
    bool ok = 1;
    int maxtower = -1;
    for (int i = 1; i <= n; i++) cnum[i] = 0, tower[i] = -1;
    for (int i = 0; i < n; i++) {
      if (cycle[i] != -1) {
        if (precycle[i] == 0) cnum[cycle[i]]++;
        tower[cycle[i]] = max(tower[cycle[i]], precycle[i]);
      }
      maxtower = max(maxtower, precycle[i]);
    }
    cnum[0] = 0;
    tower[0] = -1;
    for (int i = 1; i <= n; i++) cnum[i] = cnum[i] / i + (cnum[i] % i ? 1 : 0);
    for (int i = 0; i < n; i++)
      if (cycle[i] != -1) {
        cnum[cycle[i]] = max(cnum[cycle[i]], 1);
        tower[cycle[i]] = max(tower[cycle[i]], 0);
      }
    cnum[fixi] = max(1, cnum[fixi]);
    tower[fixi] = max(tower[fixi], maxtower);
    int vcnt = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < cnum[i] && vcnt < n * 2; j++)
        for (int k = 0; k < i && vcnt < n * 2; k++)
          format[vcnt++] = make_pair(i, 0);
      if (cnum[i] > 0) {
        for (int j = 1; j <= tower[i] && vcnt < n * 2; j++)
          format[vcnt++] = make_pair(i, j);
      }
    }
    if (vcnt > n) continue;
    for (int i = 0; i < n; i++) con[i].clear();
    for (int i = 0; i < vcnt; i++) {
      for (int j = 0; j < n; j++)
        if ((precycle[j] == -1 || precycle[j] == format[i].second) &&
            (cycle[j] == -1 || cycle[j] == format[i].first))
          con[j].push_back(i);
    }
    for (int i = 0; i < vcnt; i++) match2[i] = -1;
    F = 1;
    for (int i = 0; i < n; i++) used[i] = 0;
    for (int i = 0; i < n; i++) {
      F++;
      dfs(ord[i]);
    }
    for (int i = 0; i < n; i++) match[i] = -1;
    for (int j = 0; j < vcnt; j++)
      if (match2[j] != -1) match[match2[j]] = j;
    vector<int> covered(vcnt, -1);
    for (int i = 0; i < n; i++)
      if (match[i] != -1) covered[match[i]] = i;
    for (int i = 0; i < vcnt; i++)
      if (covered[i] == -1) {
        ok = 0;
      }
    if (!ok) continue;
    vector<int> ans(n, -1);
    for (int i = 1; i <= n; i++) {
      if (cnum[i] > 0) {
        vector<int> cur;
        for (int j = 0; j < n; j++)
          if (match[j] != -1 && format[match[j]] == make_pair(i, 0))
            cur.push_back(j);
        if ((int)cur.size() % i != 0) return 0;
        for (int j = 0; j < (int)cur.size(); j++)
          if (j % i == 0)
            ans[cur[j]] = cur[j + i - 1];
          else
            ans[cur[j]] = cur[j - 1];
      }
    }
    for (int i = 0; i < n; i++) {
      if (ans[i] == -1) {
        int a = cycle[i];
        int b = precycle[i];
        if (match[i] != -1) {
          a = format[match[i]].first;
          b = format[match[i]].second;
        }
        for (int j = 0; j < vcnt; j++)
          if ((a == -1 || format[j].first == a) &&
              (b == -1 || format[j].second == b - 1))
            ans[i] = covered[j];
        if (ans[i] == -1) {
          if (!(precycle[i] <= 0 && cycle[i] <= 1)) {
            cerr << precycle[i] << ' ' << cycle[i] << endl;
            return 0;
          }
          ans[i] = i;
        }
      }
    }
    for (int i = 0; i < n; i++) cout << ans[i] + 1 << " \n"[i == n - 1];
    return 0;
  }
  cout << -1 << endl;
  return 0;
}
