#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  bool f = 1;
  cin >> n >> m;
  vector<int> no(n, -1);
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    --s[i];
  }
  for (int i = 0; i < m; ++i) {
    if (no[s[i]] == -1 || no[s[i]] == c[i])
      no[s[i]] = c[i];
    else {
      f = 0;
      break;
    }
  }
  if (no[0] == 0) f = 0;
  if (f) {
    for (int i = 0; i < n; ++i) {
      if (no[i] == -1) no[i] = 0;
    }
  }
  if (no[0] == 0) no[0] = 1;
  if (f)
    for (int i : no) cout << i;
  else
    cout << -1;
  return 0;
}
