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