#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long mod9 = 1000000009;
signed main() {
  long long n;
  long long m;
  cin >> n >> m;
  long long s[5];
  long long c[5];
  for (long long i = 0; i < (m); i++) cin >> s[i] >> c[i];
  vector<long long> a(n + 1);
  for (long long i = 0; i < (n + 1); i++) a[i] = -1;
  long long ans = 0;
  for (long long i = 0; i < (m); i++) {
    if (a[s[i]] == -1)
      a[s[i]] = c[i];
    else if (a[s[i]] != c[i]) {
      ans = -1;
      break;
    }
  }
  if (a[1] == 0 && n != 1) ans = -1;
  if (ans != -1) {
    if (a[1] == -1) a[1] = 1;
    for (long long i = 0; i < (n); i++) {
      if (a[i + 1] == -1) a[i + 1] = 0;
      ans += a[i + 1];
      if (i != n - 1) ans *= 10;
    }
  }
  cout << ans << endl;
}
