#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> v(5, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (v[s] == -1)
      v[s] = c;
    else {
      if (v[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (N == 1 && v[1] == 0) {
    cout << 0 << endl;
    return 0;
  }
  int ans;
  if (v[1] == -1)
    ans = 1;
  else if (v[1] == 0) {
    cout << -1 << endl;
    return 0;
  } else
    ans = v[1];
  for (int i = 2; i <= N; i++) {
    ans *= 10;
    if (v[i] != -1) ans += v[i];
  }
  cout << ans << endl;
  return 0;
}
