#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long num[n];
  fill(num, num + n, 0);
  long long a, b, ans = 0;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (a == 1 && b == 0) {
      break;
    }
    if (num[a - 1] != 0) {
      if (num[a - 1] != b) {
        break;
      }
    }
    num[a - 1] = b;
    if (i == m - 1) {
      ans = 1;
    }
  }
  if (num[0] == 0) {
    num[0] = 1;
  }
  if (ans == 1) {
    for (int i = 0; i < n; i++) {
      cout << num[i];
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
}
