#include <bits/stdc++.h>
constexpr auto mod = 1000000007;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> ans(n);
  for (int i = 0; i < (int)(n); i++) {
    ans[i] = -1;
  }
  int f = 0;
  for (int i = 0; i < (int)(m); i++) {
    if (ans[s[i] - 1] == -1) {
      ans[s[i] - 1] = c[i];
    } else if (ans[s[i] - 1] != c[i]) {
      f = 1;
      break;
    }
  }
  if (ans[0] == 0) {
    f = 1;
  }
  if (f == 1) {
    cout << -1;
  } else {
    for (int i = 0; i < (int)(n); i++) {
      if (ans[i] == -1 && i != 0) {
        cout << 0;
      } else if (ans[i] == -1 && i == 0) {
        cout << 1;
      } else {
        cout << ans[i];
      }
    }
  }
}
