#include <bits/stdc++.h>
using namespace std;
mt19937 mrand(random_device{}());
const long long mod = 1000000007;
int rnd(int x) { return mrand() % x; }
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int t;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  int s[10], c[10];
  int num[10];
  memset(num, -1, sizeof(num));
  cin >> n >> m;
  bool flag = true;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (num[s[i]] != -1 && num[s[i]] != c[i]) {
      flag = false;
    }
    num[s[i]] = c[i];
  }
  if (!flag)
    cout << -1 << endl;
  else {
    if (num[1] == 0 && n == 1)
      cout << 0 << endl;
    else {
      if (num[1] == 0)
        cout << -1 << endl;
      else {
        for (int i = 1; i < n + 1; i++) {
          if (i == 1 && num[i] == -1)
            cout << 1;
          else
            cout << (num[i] == -1 ? 0 : num[i]);
        }
        cout << endl;
      }
    }
  }
  return 0;
}
