#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
using vi = vector<long long>;
const long long MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;
long long N, M;
string S;
vi va, vb;
long long C[7];
void input() {
  bool exist = true;
  for (long long i = (long long)(0); i <= (long long)(6); ++i) {
    C[i] = -1;
  }
  cin >> N >> M;
  for (long long i = (long long)(1); i <= (long long)(M); ++i) {
    long long s, c;
    cin >> s >> c;
    if ((s == 1) && (c == 0)) {
      exist = false;
      break;
    }
    if ((C[s] == -1) || C[s] == c) {
      C[s] = c;
    } else {
      cout << -1 << endl;
      exist = false;
      return;
      break;
    }
  }
  if (exist == false) {
    cout << -1 << endl;
    return;
  }
  for (long long i = (long long)(1); i <= (long long)(N); ++i) {
    if (C[i] != -1) {
      cout << C[i];
    } else {
      if (i == 1) {
        cout << 1;
      } else
        cout << 0;
    }
  }
  cout << endl;
}
void solve() {
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}
