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