#include <bits/stdc++.h>
using namespace std;
const int Maxn = 310;
const int inf = 1 << 23;
int _min(int x, int y) { return x < y ? x : y; }
int _max(int x, int y) { return x > y ? x : y; }
void read(int &x) {
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '?') {
      x = -1;
      return;
    }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
int n;
int prec[Maxn], cyc[Maxn];
int cs[Maxn], t[Maxn];
int num[Maxn][Maxn], u[Maxn][Maxn], maxx[Maxn];
vector<int> vec[Maxn];
struct node {
  int y, next, c, opp;
} a[Maxn * Maxn << 2];
int first[Maxn << 1], len, cnt;
void ins(int x, int y, int c) {
  len++;
  int k1 = len;
  a[len].y = y;
  a[len].c = c;
  a[len].next = first[x];
  first[x] = len;
  len++;
  int k2 = len;
  a[len].y = x;
  a[len].c = 0;
  a[len].next = first[y];
  first[y] = len;
  a[k1].opp = k2;
  a[k2].opp = k1;
}
int st, ed, h[Maxn << 1];
bool bfs() {
  queue<int> q;
  memset(h, -1, sizeof(h));
  h[st] = 0;
  q.push(st);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int k = first[x]; k; k = a[k].next) {
      int y = a[k].y;
      if (h[y] == -1 && a[k].c > 0) {
        h[y] = h[x] + 1;
        q.push(y);
      }
    }
  }
  return h[ed] > 0;
}
int dfs(int x, int flow) {
  if (x == ed) return flow;
  int delta = 0;
  for (int k = first[x]; k; k = a[k].next) {
    int y = a[k].y;
    if (h[y] == h[x] + 1 && a[k].c > 0 && flow - delta > 0) {
      int minf = dfs(y, _min(a[k].c, flow - delta));
      delta += minf;
      a[k].c -= minf;
      a[a[k].opp].c += minf;
    }
  }
  if (delta == 0) h[x] = -1;
  return delta;
}
int ans[Maxn];
void construct() {
  int i, j, k;
  for (i = 1; i <= n; i++) {
    if (prec[i] != -1 && cyc[i] != -1) {
      if (prec[i] == 0) vec[cyc[i]].push_back(i);
      u[cyc[i]][prec[i]] = i;
    }
  }
  for (i = 1; i <= n; i++) {
    if (vec[i].size() > 0) {
      for (j = 0; j < vec[i].size(); j += i) {
        for (k = 0; k < i; k++) ans[vec[i][j + k]] = vec[i][j + ((k + 1) % i)];
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (prec[i] == -1 && cyc[i] != -1) {
      ans[i] = u[cyc[i]][0];
    } else if (prec[i] != -1 && cyc[i] == -1) {
      if (prec[i] == 0)
        ans[i] = i;
      else
        for (j = 1; j <= n; j++)
          if (u[j][prec[i] - 1]) {
            ans[i] = u[j][prec[i] - 1];
            break;
          }
    } else if (prec[i] == -1 && cyc[i] == -1)
      ans[i] = i;
    else {
      if (prec[i] > 0) ans[i] = u[cyc[i]][prec[i] - 1];
    }
  }
  for (i = 1; i <= n; i++) printf("%d ", ans[i]);
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  int po = 1;
  for (i = 1; i <= n; i++) {
    read(prec[i]);
    read(cyc[i]);
    if (prec[i] == 0 && cyc[i] != -1) cs[cyc[i]]++;
    if (cyc[i] != -1) t[cyc[i]]++;
    if (prec[i] != -1 && cyc[i] != -1) {
      u[cyc[i]][prec[i]] = i;
      maxx[cyc[i]] = _max(maxx[cyc[i]], prec[i]);
    }
    if (prec[i] > prec[po] || (prec[i] == prec[po] && cyc[i] != -1)) po = i;
  }
  if (cyc[po] != -1) {
    int xq = 0;
    int st = 0;
    ed = 2 * n + 1;
    cnt = 0;
    memset(num, 0, sizeof(num));
    for (i = 1; i <= n && xq <= n; i++) {
      if (t[i] > 0) {
        if (cs[i] == 0)
          ins((num[i][0] = ++cnt) + n, ed, i), xq += i;
        else if (cs[i] % i != 0)
          ins((num[i][0] = ++cnt) + n, ed, i - (cs[i] % i)),
              xq += i - (cs[i] % i);
      }
    }
    for (i = 1; i <= n && xq <= n; i++) {
      if (t[i] > 0) {
        for (j = 1; j <= maxx[i] && xq <= n; j++) {
          if (!u[i][j]) {
            num[i][j] = ++cnt;
            xq++;
            ins(num[i][j] + n, ed, 1);
          }
        }
      }
    }
    if (xq > n) {
      printf("-1\n");
      return 0;
    }
    for (i = 1; i <= n; i++) {
      ins(st, i, 1);
      if (prec[i] == -1 && cyc[i] == -1) {
        for (j = 1; j <= cnt; j++) ins(i, j + n, 1);
      } else if (prec[i] == -1 && cyc[i] != -1) {
        for (j = 0; j <= maxx[cyc[i]]; j++)
          if (num[cyc[i]][j]) ins(i, num[cyc[i]][j] + n, 1);
      } else if (prec[i] != -1 && cyc[i] == -1) {
        for (j = 1; j <= n; j++)
          if (num[j][prec[i]]) ins(i, num[j][prec[i]] + n, 1);
      }
    }
    int delta = 0;
    while (bfs()) delta += dfs(st, inf);
    if (delta == xq) {
      for (i = 1; i <= n; i++) {
        for (j = 0; j <= maxx[i]; j++) {
          if (!num[i][j]) continue;
          int x = num[i][j] + n;
          for (k = first[x]; k; k = a[k].next) {
            if (a[k].y <= n && a[k].c > 0) prec[a[k].y] = j, cyc[a[k].y] = i;
          }
        }
      }
      construct();
    } else
      printf("-1\n");
  } else {
    bool bk = false;
    for (int qq = 1; qq <= n && !bk; qq++) {
      int xq = 0;
      int st = 0;
      ed = 2 * n + 1;
      cnt = 0;
      len = 0;
      memset(first, 0, sizeof(first));
      memset(num, 0, sizeof(num));
      for (i = 1; i <= n && xq <= n; i++) {
        if (t[i] > 0 || i == qq) {
          if (cs[i] == 0)
            ins((num[i][0] = ++cnt) + n, ed, i), xq += i;
          else if (cs[i] % i != 0)
            ins((num[i][0] = ++cnt) + n, ed, i - (cs[i] % i)),
                xq += i - (cs[i] % i);
        }
      }
      for (i = 1; i <= n && xq <= n; i++) {
        if (t[i] > 0 || i == qq) {
          int r = maxx[i];
          if (i == qq) r = prec[po];
          for (j = 1; j <= r && xq <= n; j++) {
            if (!u[i][j]) {
              num[i][j] = ++cnt;
              xq++;
              ins(num[i][j] + n, ed, 1);
            }
          }
        }
      }
      if (xq > n) continue;
      for (i = 1; i <= n; i++) {
        ins(st, i, 1);
        if (prec[i] == -1 && cyc[i] == -1) {
          for (j = 1; j <= cnt; j++) ins(i, j + n, 1);
        } else if (prec[i] == -1 && cyc[i] != -1) {
          int r = maxx[cyc[i]];
          if (cyc[i] == qq) r = prec[po];
          for (j = 0; j <= r; j++)
            if (num[cyc[i]][j]) ins(i, num[cyc[i]][j] + n, 1);
        } else if (prec[i] != -1 && cyc[i] == -1) {
          for (j = 1; j <= n; j++)
            if (num[j][prec[i]]) ins(i, num[j][prec[i]] + n, 1);
        }
      }
      int delta = 0;
      while (bfs()) delta += dfs(st, inf);
      if (delta == xq) {
        for (i = 1; i <= n; i++) {
          int r = maxx[i];
          if (i == qq) r = prec[po];
          for (j = 0; j <= r; j++) {
            if (!num[i][j]) continue;
            int x = num[i][j] + n;
            for (k = first[x]; k; k = a[k].next) {
              if (a[k].y <= n && a[k].c > 0) prec[a[k].y] = j, cyc[a[k].y] = i;
            }
          }
        }
        maxx[qq] = prec[po];
        construct();
        bk = true;
      }
    }
    if (!bk) printf("-1");
  }
  return 0;
}
