#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double PI = acos(-1);
const long long MOD = 1000000007;
const long long FMOD = 998244353;
const long double eps = 1e-9;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
  long long n, m;
  cin >> n >> m;
  long long a[n];
  for (long long i = 0; i < n; i++) a[i] = -1;
  for (long long i = 0; i < m; i++) {
    long long idx, num;
    cin >> idx >> num;
    idx--;
    if (a[idx] == -1) {
      a[idx] = num;
    } else {
      if (a[idx] != num) {
        cout << -1;
        return 0;
      }
    }
  }
  long long cnt = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] != 0) break;
    cnt++;
  }
  if (n == 1) {
    cout << a[0];
  } else {
    if (cnt)
      cout << -1;
    else {
      for (long long i = 0; i < n; i++) {
        if (a[i] == -1)
          cout << 0;
        else
          cout << a[i];
      }
    }
  }
}
