#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 100000000;
const double PI = acos(-1);
int main() {
  int N, M;
  cin >> N >> M;
  int s[M];
  char c[M];
  string ans;
  for (int i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    ans.push_back('X');
  }
  for (int i = 0; i < (M); i++) {
    if (ans[s[i]] == 'X' || ans[s[i]] == c[i]) {
      ans[s[i]] = c[i];
    } else {
      ans = "-1";
      break;
    }
  }
  if (ans == "-1") {
    cout << -1 << endl;
  } else if (N > 1 && ans[0] == '0') {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < (N); i++) {
      if (ans[i] == 'X') {
        ans[i] = '0';
      }
    }
    cout << ans << endl;
  }
}
