#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m, k;
  k = 0;
  cin >> n >> m;
  vector<int> s(m), c(m);
  string newans = "";
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
  }
  vector<int> ans(n + 1, -1);
  for (int i = 0; i < (m); ++i) {
    if (ans[s[i]] != -1 and ans[s[i]] != c[i]) {
      k = 1;
      break;
    } else {
      ans[s[i]] = c[i];
    }
  }
  if (ans[1] == 0) {
    k = 2;
  }
  if (ans[1] == -1) {
    ans[1] = 1;
  }
  if (k == 0) {
    for (int i = 0; i < (n - 1); ++i) {
      if (ans[i + 2] == -1) {
        ans[i + 2] = 0;
      }
      newans = newans + to_string(ans[i + 1]);
    }
    cout << newans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
