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