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