#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main(void) {
  int n, m;
  cin >> n >> m;
  map<int, int> num;
  for (int i = 1; i <= 3; i++) num[i] = -1;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      if (n == 1) {
        cout << 0 << endl;
        return 0;
      }
      cout << -1 << endl;
      return 0;
    }
    if (num[s] != -1 && num[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    num[s] = c;
  }
  string ans = "";
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      if (num[i] == -1) {
        ans += '1';
        continue;
      }
      ans += to_string(num[i]);
      continue;
    }
    if ((num[i] == -1)) {
      ans += '0';
      continue;
    }
    ans += to_string(num[i]);
  }
  cout << ans << endl;
  return 0;
}
