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