#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
void solv() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  int a[7];
  for (int i = 0; i < 7; i++) {
    a[i] = -1001001001;
  }
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    s.at(i)--;
    c.at(i);
  }
  for (int i = 0; i < M; i++) {
    if (a[s[i]] == -1001001001) {
      a[s[i]] = c[i];
    } else if (a[s[i]] != c[i]) {
      cout << "-1" << endl;
      return;
    }
  }
  if (a[0] == 0) {
    cout << "-1" << endl;
    return;
  }
  for (int i = 0; i < N; i++) {
    if (a[i] == -1001001001) {
      a[i] = 0;
    }
    cout << a[i];
  }
  cout << endl;
}
int main() {
  solv();
  return 0;
}
