#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  int ans[N];
  for (int i = 0; i < (N); i++) {
    ans[i] = -1;
  }
  bool flag = true;
  for (int i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
    if (ans[s[i] - 1] != -1 && ans[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      flag = false;
    }
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == 0) {
    if (N > 1)
      cout << -1 << endl;
    else
      cout << 0 << endl;
  } else if (flag) {
    bool flag2 = false;
    for (int i = 0; i < (N); i++) {
      if (ans[i] == -1) {
        if (i == 0) {
          cout << 1;
          flag2 = true;
        } else if (flag2 && ans[i] == -1) {
          cout << 1;
        } else {
          cout << 0;
          flag2 = false;
        }
      } else {
        cout << ans[i];
      }
    }
    cout << endl;
  }
  return 0;
}
