#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  string S = "";
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      S += "1";
    } else {
      S += "0";
    }
  }
  pair<int, int> sc[M];
  vector<bool> change(M, false);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    sc[i] = make_pair(a, b);
  }
  int ans = 0;
  if (M == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    int index = sc[i].first - 1;
    int value = sc[i].second;
    if (change[index] == false) {
      S[index] = value + '0';
      change[index] = true;
    } else if (change[index] == true && S[index] == value + '0') {
      continue;
    } else {
      ans = -1;
    }
  }
  if (S[0] == '0' && S.size() != 1) {
    ans = -1;
  }
  if (ans != -1) {
    ans = stoi(S);
  }
  cout << ans << endl;
  return 0;
}
