#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  string ans;
  cin >> n >> m;
  unordered_map<int, int> sc(m);
  unordered_map<int, bool> flag(m);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (sc[s] != c && flag[s]) {
      cout << -1 << "\n";
      return 0;
    } else {
      sc[s] = c;
      flag[s] = true;
    }
  }
  if (sc[0] != 0) {
    for (int i = 0; i < n; i++) {
      ans += to_string(sc[i]);
    }
  } else {
    cout << -1 << "\n";
    return 0;
  }
  cout << ans << "\n";
}
