#include <bits/stdc++.h>
using namespace std;
bool check1(int N, int s, int c) {
  if (N > 1 && s == 1 && c == 0) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int s, c;
  vector<int> ans(N, 0);
  vector<bool> check(N, false);
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (check[s - 1] && ans[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    if (check1(N, s, c)) {
      cout << -1 << endl;
      return 0;
    }
    check[s - 1] = true;
    ans[s - 1] = c;
  }
  if (!check[0]) ans[0]++;
  for (int i = 0; i < N; i++) cout << ans[i];
  cout << endl;
  return 0;
}
