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