#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, tmp1, tmp2;
  cin >> n >> m;
  int a[n + 1];
  fill(a, a + n + 1, -1);
  for (int i = 0; i < m; i++) {
    cin >> tmp1 >> tmp2;
    if (a[tmp1] == -1) {
      a[tmp1] = tmp2;
    } else if (a[tmp1] != tmp2) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[1] == -1) {
    a[1] = 1;
  }
  if (a[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 2; i < n + 1; i++) {
    if (a[i] == -1) a[i] = 0;
  }
  for (int i = 1; i < n + 1; i++) {
    if (a[i] != 0 || n == 1) break;
    if (i == n) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i < n + 1; i++) cout << a[i];
  cout << endl;
}
