#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (ll i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[s] != -1 && c != ans[s]) {
      cout << -1 << endl;
      return 0;
    }
    ans[s] = c;
  }
  for (int c : ans) {
    if (c == -1) c = 1;
    cout << c;
  }
  cout << endl;
  return 0;
}
