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