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