#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
using pear = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n);
  ans[0] = 1;
  vector<bool> already(n);
  for (int i = 0; i < (int)(n); i++) already[i] = false;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (already[s] && ans[s] != c) {
      cout << -1 << endl;
      return 0;
    } else {
      already[s] = true;
      ans[s] = c;
    }
  }
  for (int i = 0; i < (int)(n); i++) cout << ans[i];
  cout << "" << endl;
}
