#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll powll(ll a, ll n) {
  if (n == 0) {
    return 1;
  }
  return powll(a, n - 1) * a;
}
int main() {
  ll i, j, k;
  ll n, m, s[10], c[10], num[5];
  cin >> n >> m;
  for (i = 0; i < 3; i++) {
    num[i] = -1;
  }
  vector<int> ins;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ins.push_back(a);
    ins.push_back(b);
  }
  for (i = 0; i < m; i++) {
    ll a = ins[i * 2], b = ins[i * 2 + 1];
    a = n - a;
    if (a < 0) {
      cout << -1 << endl;
      return 0;
    }
    if (num[a] != -1 && num[a] != b) {
      cout << -1 << endl;
      return 0;
    }
    if (a == n - 1 && b == 0) {
      if (n != 1) {
        cout << -1 << endl;
        return 0;
      }
    }
    num[a] = b;
  }
  if (num[n - 1] == -1) {
    cout << 1;
  } else {
    cout << num[n - 1];
  }
  for (i = n - 2; i >= 0; i--) {
    if (num[i] == -1) {
      cout << 0;
    } else {
      cout << num[i];
    }
  }
  cout << endl;
}
