#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using dl = long double;
int main() {
  int n, m;
  int flag = 0;
  cin >> n >> m;
  int arr[3] = {-1, -1, -1};
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (n > 1 && a == 1 && b == 0) {
      flag = 1;
    }
    if (arr[a - 1] == -1 || arr[a - 1] == b) {
      arr[a - 1] = b;
    } else {
      flag = 1;
    }
  }
  if (flag == 1)
    cout << -1;
  else {
    for (int i = 0; i < n; i++) {
      if (arr[i] == -1)
        cout << 0;
      else {
        cout << arr[i];
      }
    }
  }
  return 0;
}
