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