#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vll a(n, -1);
  ll s, c, zero = 0;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (a[s] != c && a[s] != -1) {
      cout << -1 << endl;
      return 0;
    }
    if (s == 0 && c == 0) {
      if (n != 1) {
        cout << -1 << endl;
        return 0;
      }
    }
    a[s] = c;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == -1) a[i] = 0;
    cout << a[i];
  }
  cout << endl;
  return 0;
}
