#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (i = 0; i < m; i++) cin >> s[i] >> c[i];
  vector<long long> t(4, -1ll);
  for (i = 0; i < m; i++) {
    if (t[s[i]] == -1 || t[s[i]] == c[i])
      t[s[i]] = c[i];
    else {
      cout << -1;
      return 0;
    }
  }
  if (t[1] == -1) t[1] = 1;
  for (i = 2; i <= n; i++) {
    if (t[i] == -1) t[i] = 0;
  }
  if (t[1] == 0) {
    cout << -1;
    return 0;
  } else {
    long long ans = t[1];
    for (i = 2; i <= n; i++) ans = ans * 10 + t[i];
    cout << ans;
  }
}
