#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18, MOD = 1e9 + 7;
const int iINF = 1e9;
int ans[4][4];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  bool flag = false;
  cin >> n >> m;
  vector<int> s(m), c(m);
  map<pair<int, int>, int> mp;
  map<int, int> check;
  for (long long i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0 && n != 1) flag = true;
    mp[{s[i], c[i]}]++;
    check[s[i]]++;
    if (mp[{s[i], c[i]}] != check[s[i]]) flag = true;
  }
  if (flag)
    cout << -1 << endl;
  else {
    string ans(n, '0');
    for (long long i = 0; i < (m); i++) {
      ans[s[i] - 1] = '0' + c[i];
    }
    if (ans[0] == '0') ans[0] = '1';
    cout << ans << endl;
  }
}
