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