#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
void ABC157C() {
  int N, M;
  cin >> N >> M;
  vi A(N, -1);
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (A[s] > -1 && A[s] != c) {
      cout << "-1" << endl;
      return;
    }
    A[s] = c;
  }
  if (N > 1 && A[0] <= 0) {
    cout << "-1" << endl;
    return;
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans *= 10;
    ans += max(A[i], 0);
  }
  cout << ans << endl;
}
int main() {
  ABC157C();
  return 0;
}
