#include <bits/stdc++.h>
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> n(N);
  for (int i = 0; i < N; i++) {
    n[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (n[s - 1] > 0 && n[s - 1] != c) {
      cout << "-1" << endl;
      return 0;
    } else {
      n[s - 1] = c;
    }
  }
  if (n[0] == 0) {
    cout << "-1" << endl;
    return 0;
  } else {
    cout << max(n[0], 1);
    for (int i = 1; i < N; i++) {
      cout << max(n[i], 0);
    }
    cout << endl;
    return 0;
  }
}
