#include <bits/stdc++.h>
const long long INF = 1000000007;
using namespace std;
int main() {
  long long N, M;
  long long s, c;
  string ans = "";
  char num;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    ans = ans + '0';
  }
  map<long long, long long> dict;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (dict[s] && dict[s] != c) {
      cout << -1 << endl;
      exit(0);
    }
    dict[s] = c;
  }
  for (auto x : dict) {
    s = x.first;
    c = x.second;
    num = (char)c + '0';
    ans[s - 1] = num;
  }
  if (ans[0] == '0' && ans.size() != 1) {
    cout << -1 << endl;
    exit(0);
  }
  cout << ans << endl;
  return 0;
}
