#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  bool flag = false;
  vector<int> ans(N, -1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (ans[a] != -1 && ans[a] != b)
      flag = true;
    else
      ans[a] = b;
  }
  if (ans[0] == 0)
    flag = true;
  else if (ans[0] == -1)
    ans[0] = 1;
  if (flag)
    cout << -1 << endl;
  else {
    for (int i = 0; i < N; i++) cout << (ans[i] != -1 ? ans[i] : 0);
  }
  cout << endl;
  return 0;
}
