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