#include <bits/stdc++.h>
using namespace std;
long long n, m, f[200005], ww, a, b;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    f[i] = -1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (f[a] == -1) {
      f[a] = b;
      continue;
    }
    if (f[a] != -1 && f[a] != b) {
      ww = 1;
      continue;
    }
    if (f[a] != -1 && f[a] == b) {
      f[a] = b;
      continue;
    }
  }
  if (ww == 1 || f[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 1) {
    cout << f[1] << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (f[i] != -1) {
      cout << f[i];
      continue;
    }
    if (f[i] == -1) {
      if (i == 1) {
        cout << 1;
        continue;
      }
      cout << 0;
    }
  }
}
