#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long m, n;
  long long total = 0;
  cin >> n >> m;
  vector<long long> s(m);
  vector<long long> c(m);
  for (long long i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  vector<long long> num(n, -1);
  for (int i = 0; i < m; i++) {
    if (num[s[i] - 1] != -1 && num[s[i] - 1] != c[i]) {
      cout << -1;
      return 0;
    }
    num[s[i] - 1] = c[i];
  }
  if (num[0] == 0) {
    cout << -1;
    return 0;
  }
  if (num[0] == -1) num[0] = 1;
  for (int x : num) {
    if (x == -1) x = 0;
    cout << x;
  }
  return 0;
}
