#include <bits/stdc++.h>
using namespace std;
string s;
int f[10];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  s = string(n, '0');
  for (int i = 0; i < m; i++) {
    int p, v;
    cin >> p >> v;
    if (f[p - 1] && s[p - 1] != ('0' + v)) {
      cout << -1 << '\n';
      return 0;
    }
    s[p - 1] = '0' + v;
    f[p - 1] = 1;
  }
  int sm = 0;
  for (int i = 0; i < n; i++) sm += (s[i] - '0');
  if (sm == 0)
    cout << -1 << '\n';
  else
    cout << s << '\n';
}
