#include <bits/stdc++.h>
using namespace std;
static const long long INF = 1000000000000000000LL;
static const long long MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> kimari(N, -1);
  for (long long i = 0; i < (M); i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (kimari[s] != -1 && kimari[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    kimari[s] = c;
  }
  string res = "";
  if (N != 1) {
    if (kimari[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long i = 0; i < (N); i++) {
    if (kimari[i] != -1) {
      res += to_string(kimari[i]);
    } else {
      char tmp;
      if (i != 0)
        tmp = '0';
      else
        tmp = '1';
      res += tmp;
    }
  }
  cout << res << endl;
  return 0;
}
