#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n + 1, -1), s, c;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    s.push_back(x);
    c.push_back(y);
    ans[x] = y;
  }
  for (int i = 0; i < m; i++) {
    int x = s[i];
    int y = c[i];
    if (ans[x] != y) {
      cout << "-1";
      return 0;
    }
  }
  for (int i = 2; i <= n; i++) {
    if (ans[i] == -1) {
      ans[i] = 0;
    }
  }
  if (ans[1] == 0 and n > 1) {
    cout << "-1";
  } else {
    if (ans[1] == -1) {
      ans[1] = 1;
    }
    for (int i = 1; i <= n; i++) {
      cout << ans[i];
    }
  }
}
