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