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