#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> mp;
  bool flag = true;
  for (int m = 0; m < M; m++) {
    int s, c;
    cin >> s >> c;
    if (!flag) continue;
    if (mp.find(s) != mp.end()) {
      if (mp[s] != c) {
        flag = false;
      }
    } else {
      mp[s] = c;
      if (N >= 2 && s == 1) {
        if (c == 0) {
          flag = false;
        }
      }
    }
  }
  int ans = 0;
  if (flag) {
    int pow = 1;
    for (int n = 1; n < N; n++) {
      pow *= 10;
    }
    for (int i = 1; i <= N; i++) {
      if (i == 1 && mp[i] == 0) mp[i]++;
      ans += pow * mp[i];
      pow /= 10;
    }
  } else {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
