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