#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long a[n + 1];
    memset(a, -1, sizeof a);
    long long idx, x;
    bool cond = true;
    for (long long i = 0; i < m; i++) {
      cin >> idx >> x;
      if (a[idx] == -1)
        a[idx] = x;
      else {
        if (a[idx] != x) cond = false;
      }
    }
    if (n == 1) {
      cout << (a[1] == -1 ? 0 : a[0]) << endl;
      continue;
    }
    if (a[1] == 0) cond = false;
    if (cond) {
      for (long long i = 1; i <= n; i++)
        cout << ((a[i] == -1) ? ((i == 1) ? 1 : 0) : a[i]);
      cout << endl;
    } else
      cout << -1 << endl;
  }
  return 0;
}
