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