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