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