#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m, cnt = 0;
  cin >> n >> m;
  vector<int> num(n);
  vector<bool> ketacheck(n, false);
  for (int i = 0; i < m; i++) {
    int st, ct;
    cin >> st >> ct;
    if (ketacheck[st - 1] == true and num[st - 1] != ct) {
      cout << -1 << endl;
      return 0;
    } else if (st == 1 and ct == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      num[st - 1] = ct;
      ketacheck[st - 1] = true;
    }
  }
  if (ketacheck[0] == false) {
    num[0] = 1;
    ketacheck[0] == true;
  }
  for (int i = 0; i < n; i++) {
    if (ketacheck[i] == false) {
      num[i] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = ans * 10 + num[i];
  }
  cout << ans << endl;
}
