#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  bool check = true;
  int n, m;
  cin >> n >> m;
  int s[10], c[10];
  string st;
  for (int i = 0; i < n; i++) {
    st[i] = 'a';
  }
  if (n != 1) {
    for (int i = 0; i < m; i++) {
      cin >> s[i] >> c[i];
      s[i]--;
      if (s[i] == 0 && c[i] == 0) {
        check = false;
      }
      if ((st[s[i]] != 'a') && (st[s[i]] != c[i] + '0')) {
        check = false;
      }
      st[s[i]] = c[i] + '0';
    }
    if (!check) {
      cout << -1 << "\n";
    } else {
      if (st[0] == 'a') {
        cout << '1';
      } else {
        cout << st[0];
      }
      for (int i = 1; i < n; i++) {
        if (st[i] == 'a') {
          cout << 0;
        } else {
          cout << st[i];
        }
      }
      cout << "\n";
    }
  } else {
    for (int i = 0; i < m; i++) {
      cin >> s[i] >> c[i];
      if ((st[0] != 'a') && (st[0] != c[i] + '0')) {
        check = false;
      }
      st[0] = c[i] + '0';
    }
    if (!check) {
      cout << -1 << "\n";
    } else {
      cout << st[0] << "\n";
    }
  }
}
