#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main(void) {
  fast();
  int n, m;
  cin >> n >> m;
  int flag = 0;
  vector<int> v(n, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 0) {
      flag = -1;
    } else if (flag == 0 || v[a - 1] == b) {
      flag = 1;
      v[a - 1] = b;
    } else if (flag == 1 && v[a - 1] == b) {
      flag = -1;
    } else {
      v[a - 1] = b;
    }
  }
  if (flag == -1 || v[0] == 0) {
    cout << -1 << "\n";
  } else {
    for (int i = 0; i < v.size(); i++) {
      cout << v[i];
    }
    cout << "\n";
  }
}
