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