#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;
    else {
      if (f[a] != b) {
        ww = 1;
      }
    }
  }
  if (ww == 1 || f[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 1 && f[1] == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (f[i] == -1 && i != 1)
      cout << 0;
    else if (f[i] == -1 && i == 1)
      cout << 1;
    else
      cout << f[i];
  }
}
