#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, string> mp;
  for (int i = 0; i < 3; i++) mp[i + 1] = "-1";
  for (int i = 0; i < m; i++) {
    int s;
    string c;
    cin >> s >> c;
    if (mp[s] != "-1" && mp[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    mp[s] = c;
  }
  string ans;
  int cnt = 1;
  for (int i = n; i > 0; i--) {
    if (i == n && mp[cnt] == "0") {
      cout << -1 << endl;
      return 0;
    }
    if (mp[cnt] == "-1")
      ans += "0";
    else
      ans += mp[cnt];
    cnt++;
  }
  cout << ans << endl;
  return 0;
}
