#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll res = 1000000007;
int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  vector<ll> s(m, 0), c(m, 0), a(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    a[s[i] - 1] = c[i];
  }
  for (int i = 0; i < m; i++) {
    if (a[s[i] - 1] != c[i]) ans = -1;
    if (s[i] == 1 and c[i] == 0 and n != 1) ans = -1;
  }
  if (ans != -1) {
    for (int i = 0; i < n; i++) {
      cout << a[i];
    }
  } else
    cout << ans << endl;
}
