#include <bits/stdc++.h>
using namespace std;
constexpr long long int linf = numeric_limits<long long int>::max() - 5;
constexpr int inf = numeric_limits<int>::max() - 5;
constexpr long long int mod = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  map<int, int> mp;
  mp[0] = -1;
  mp[1] = -1;
  mp[2] = -1;
  int tmpa, tmpb;
  for (long long int i = 0; (i) < (m); i++) {
    cin >> tmpa >> tmpb;
    if (mp[tmpa - 1] == -1 || mp[tmpa - 1] == tmpb) {
      mp[tmpa - 1] = tmpb;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if ((n == 2 || n == 3) && mp[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long int i = 0; (i) < (3); i++) {
    if (mp[i] == -1) {
      if (i == 0) {
        mp[i] = 1;
      } else {
        mp[i] = 0;
      }
    }
  }
  cout << mp[0] << mp[1] << mp[2] << endl;
  return 0;
}
