#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  map<int, int> mp;
  for (int i = 0; i < M; i++) {
    if (mp.count(s[i]) && c[i] != mp[s[i]]) {
      cout << -1 << endl;
      return 0;
    }
    mp[s[i]] = c[i];
  }
  vector<char> ans(N, '0');
  for (int i = 0; i < M; i++) {
    ans[s[i]] = c[i] + '0';
  }
  if (ans[0] == '0' && N > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i];
  }
  cout << endl;
}
