#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void solve() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  string num = "";
  for (int i = 0; i < n; i++) num += "0";
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    if (s[i] > n) {
      cout << -1 << endl;
      return;
    } else {
      if ((c[i] == 0) && (s[i] == 1)) {
        if (n == 1) {
          cout << 0 << endl;
          return;
        } else {
          cout << -1 << endl;
          return;
        }
      }
      if (num[s[i] - 1] != c[i]) {
        if (num[s[i] - 1] != '0') {
          cout << -1 << endl;
          return;
        } else {
          num[s[i] - 1] = c[i];
        }
      }
    }
  }
  if (num[0] == '0') {
    if (n == 1) {
      cout << 0 << endl;
      return;
    } else
      num[0] = '1';
  }
  cout << num << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
