#include <bits/stdc++.h>
using namespace std;
const long long MOD_CONST = 1000000007;
const long long BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> ma;
  bool canConsist = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (ma.find(s) != ma.end() && ma[s] != c) {
      canConsist = false;
      break;
    }
    ma[s] = c;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (ma.find(i) == ma.end()) {
      if (i == 1) {
        ans = ans * 10 + 1;
      } else {
        ans = ans * 10 + 0;
      }
      continue;
    }
    ans = ans * 10 + ma[i];
  }
  if (ma[1] == 0 && n != 1) {
    canConsist = false;
  }
  if (canConsist) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
