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