#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<char> num(N, 40);
  for (int i = 0; i < M; i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == '0' && N >= 2) {
      cout << -1 << endl;
      return 0;
    }
    if (num[s] == 40) {
      num[s] = c;
    } else if (num[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  string ans = "";
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      if (M == 0) {
        cout << 0 << endl;
        return 0;
      } else {
        ans = num[i] == 40 ? '1' : num[i];
      }
    } else {
      ans += num[i] == 40 ? '0' : num[i];
    }
  }
  cout << ans << endl;
  return 0;
}
