#include <bits/stdc++.h>
using namespace std;
long long mil() { return numeric_limits<long long>::min(); }
long long mal() { return numeric_limits<long long>::max(); }
int main(int argc, char **argv) {
  long long N, M;
  cin >> N >> M;
  vector<long long> cis(N, -1);
  for (long long i = 0; i < (M); ++i) {
    long long s, c;
    cin >> s >> c;
    if (cis[s - 1] < 0) {
      cis[s - 1] = c;
    } else if (cis[s - 1] >= 0 && cis[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long tot = 0;
  if (cis[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < (N); ++i) {
    tot *= 10;
    tot += cis[i] < 0 ? (i != 0 ? 0 : 1) : cis[i];
  }
  cout << tot << endl;
}
