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