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