#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  bool l = true;
  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    mp[i] = 10;
  }
  for (int i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (mp[s] != 10 && mp[s] != c) {
      l = false;
    } else {
      mp[s] = c;
    }
  }
  if (mp[1] == 10) {
    mp[1] = 1;
  } else if (mp[1] == 0 && n != 1) {
    l = false;
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      continue;
    } else {
      if (mp[i] == 10) {
        mp[i] = 0;
      }
    }
  }
  if (!l) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      cout << mp[i];
    }
  }
}
