#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> c(n);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<char> pre(n, '0');
  vector<long long> cnt(n, -1);
  string ans;
  bool ok = true;
  for (int i = 0; i < (m); i++) {
    if (cnt[s[i]] == -1)
      cnt[s[i]] = c[i];
    else if (cnt[s[i]] == c[i])
      continue;
    else {
      ans = "-1";
      ok = false;
      break;
    }
  }
  if (ok) {
    for (int i = 0; i < (m); i++) pre[s[i]] = cnt[s[i]] + '0';
    for (auto tmp : pre) ans.push_back(tmp);
    if (m == 0 && n > 1) ans[0] = '1';
    if (ans[0] == '0' && n > 1) ans = "-1";
  }
  cout << ans << endl;
  return 0;
}
