#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> d(N, -1);
  int ans = -1;
  bool flag1 = true, flag2 = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (d[s - 1] == -1 || d[s - 1] == c)
      d[s - 1] = c;
    else
      flag1 = false;
    if (s == 1 && c == 0) flag2 = false;
  }
  if (flag1 && flag2) {
    ans = max(1, d[0]);
    for (int i = 1; i < N; i++) {
      ans *= 10;
      ans += max(0, d[i]);
    }
    cout << ans << endl;
  } else if (N == 1 && d[0] == 0 && flag1)
    cout << 0 << endl;
  else
    cout << -1 << endl;
  return 0;
}
