#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, char> mp;
  bool flag = false;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (mp[a] == mp[n + 1])
      mp[a] = (char)b + '0';
    else if (mp[a] != (char)b + '0')
      flag = 1;
  }
  if (flag)
    cout << -1;
  else if (n > 1 and mp[1] == '0')
    cout << -1;
  else {
    if (mp[1] == mp[n + 1]) {
      cout << 1;
    } else {
      cout << mp[1];
    }
    for (int i = 2; i <= n; i++) {
      if (mp[i] == mp[n + 1])
        cout << 0;
      else
        cout << mp[i];
    }
  }
  cout << endl;
}
