#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
int main(void) {
  ll n, m;
  cin >> n >> m;
  string str(n, ' ');
  bool error = false;
  for (int i = 0; i < m; i++) {
    ll s;
    char c;
    cin >> s >> c;
    s = s - 1;
    if (str[s] != ' ' && c != str[s]) {
      error = true;
    }
    str[s] = c;
  }
  ll ans;
  if ((n != 1 && str[0] == '0') || error) {
    ans = -1;
  } else {
    replace_if(
        begin(str), end(str), [](char ch) { return ch == ' '; }, '0');
    ans = stoi(str);
  }
  cout << ans << endl;
  return 0;
}
