#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int flag = 0;
void monmo(int k, int n) {
  if (v[k] < 0)
    v[k] = n;
  else if (v[k] != n)
    flag = 1;
}
int main(void) {
  int n, m;
  int keta, num;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    v.push_back(-1);
  }
  for (int i = 0; i < m; i++) {
    cin >> keta >> num;
    monmo(keta - 1, num);
  }
  if (flag == 1 || v[0] == 0) {
    cout << -1;
    exit(0);
  }
  v[0] = 1;
  for (int i = 0; i < n; i++) {
    if (v[i] < 0)
      cout << 0;
    else
      cout << v[i];
  }
}
