#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  bool ok = true;
  for (int i = 0; i < (int)(m); ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (num[s] == -1)
      num[s] = c;
    else {
      if (num[s] != c) ok = false;
    }
  }
  if (num[0] == 0 && num.size() != 1) {
    ok = false;
  }
  if (!ok) {
    cout << -1 << '\n';
    return 0;
  }
  string ans;
  for (int i = 0; i < (int)(n); ++i) {
    if (num[i] == -1)
      ans += '0';
    else
      ans += num[i] + '0';
  }
  cout << ans << '\n';
  return 0;
}
