#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  string ans = "";
  bool ok = 1;
  map<int, char> digit;
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    int s;
    char c;
    cin >> s >> c;
    if (N > 1 and s == 1 and c == '0') {
      ok = 0;
      break;
    }
    if (digit.count(s)) {
      if (digit[s] != c) {
        ok = 0;
        break;
      }
    } else {
      digit[s] = c;
    }
  }
  if (ok) {
    for (int i = 1; i <= N; ++i) {
      if (digit.count(i))
        ans += digit[i];
      else
        ans += '0';
    }
    cout << ans << "\n";
  } else
    cout << "-1\n";
}
