#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
long long gcd(long long x, long long y) {
  if (x % y == 0) return y;
  return gcd(y, x % y);
}
long long LCM(int a, int b) { return a * b / gcd(a, b); }
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  for (int i = 0; i < (int)m; ++i) {
    int s, c;
    cin >> s >> c;
    if (n != s && c == 0) {
      cout << -1 << endl;
      return 0;
    } else if (num[s - 1] == -1) {
      num[s - 1] = c;
    } else if (num[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < (int)n; ++i) {
    if (num[i] == -1) num[i] = 0;
    cout << num[i];
  }
  cout << endl;
  return 0;
}
