#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  vi s(m), c(m);
  for (int i = 0, i_len = (m); i < i_len; ++i) cin >> s[i] >> c[i];
  string ans = "";
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    int a = -1;
    for (int j = 0, j_len = (m); j < j_len; ++j) {
      if (s[j] == i + 1) {
        if (a != -1) {
          if (a == c[j])
            continue;
          else {
            cout << "-1" << endl;
            return 0;
          }
        } else {
          a = c[j];
        }
      }
    }
    if (i == 0 && a == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (a == -1) {
      if (i == 0)
        ans += "1";
      else
        ans += "0";
    } else {
      ans += '0' + a;
    }
  }
  cout << ans << endl;
}
