#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = numeric_limits<long long>::max() / 2;
using Graph = vector<vector<long long>>;
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  long long A[N];
  for (long long i = 0; i < (long long)(N); i++) A[i] = -1;
  long long a, b;
  for (long long i = 0; i < (long long)(M); i++) {
    cin >> a >> b;
    --a;
    if (A[a] != -1 && A[a] != b) {
      cout << -1 << endl;
      return 0;
    } else {
      A[a] = b;
    }
  }
  if (A[0] == -1) A[0] = 1;
  if (A[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << A[0];
  for (long long i = 1; i < N; i++) {
    if (A[i] == -1) {
      cout << 0;
    } else {
      cout << A[i];
    }
  }
}
