#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 18;
const long long MAX = 200000;
const long long MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  vector<int> K(N, -1);
  bool OK = true;
  for (long long i = (0); i < (M); i++) {
    cin >> S[i] >> C[i];
    S[i]--;
    if (K[S[i]] == -1) {
      K[S[i]] = C[i];
    } else {
      if (K[S[i]] != C[i]) {
        OK = false;
      }
    }
  }
  if (!OK) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = (0); i < (N); i++) {
    if (K[i] == -1) {
      cout << (i == 0 ? 1 : 0);
    } else {
      if (i == 0 && K[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
      cout << K[i];
    }
  }
  cout << endl;
  return 0;
}
