#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<bool> changed(n, false);
  vector<int> ans(n, -1);
  for (int i = 0; i < m; i++) {
    if (changed[s[i]] && ans[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      changed[s[i]] = true;
      ans[s[i]] = c[i];
    }
  }
  if (ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  ans[0] = max(ans[0], 1);
  for (int x : ans) {
    cout << max(0, x);
  }
  cout << endl;
  return 0;
}
