#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> w(n, -1);
  bool flag = false;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (w[a - 1] == -1) {
      w[a - 1] = b;
    } else {
      if (w[a - 1] != b) {
        flag = true;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (w[i] == -1) {
      w[i] = 0;
    }
  }
  if (flag) {
    cout << -1;
    return 0;
  }
  if (w[0] == 0) {
    cout << -1;
    return 0;
  } else {
    for (int i = 0; i < n; i++) {
      cout << w[i];
    }
  }
  return 0;
}
