#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() { cout << "Yes" << '\n'; }
void No() { cout << "No" << '\n'; }
void YES() { cout << "YES" << '\n'; }
void NO() { cout << "NO" << '\n'; }
int main() {
  ll n, m;
  cin >> n >> m;
  vector<char> ans(n, '?');
  for (ll i = 0; i < m; i++) {
    ll s;
    char c;
    cin >> s >> c;
    if (s == 1 && c == '0') {
      cout << -1 << '\n';
      return 0;
    }
    if (ans[s - 1] == '?')
      ans[s - 1] = c;
    else if (ans[s - 1] != c) {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (ll i = 0; i < m; i++) {
    if (ans[i] == '?') {
      if (i == 0 && m > 1)
        cout << 1;
      else
        cout << 0;
    } else
      cout << ans[i];
  }
  cout << '\n';
}
