#include <bits/stdc++.h>
constexpr auto mod = 1000000007;
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) {
    a[i] = -1;
  }
  int flag = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (a[s[i] - 1] == -1) {
      a[s[i] - 1] = c[i];
    } else {
      if (a[s[i] - 1] != c[i]) {
        flag = -1;
      }
    }
  }
  if (flag == -1) {
    cout << -1;
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] == -1) {
        if (i == 0) {
          cout << 1;
        } else {
          cout << 0;
        }
      } else {
        cout << a[i];
      }
    }
  }
}
