#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long INF = 1000000000000000000;
int s[10], c[10];
int ans[10];
bool o[10];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < M; i++) {
    o[s[i]] = true;
    for (int j = i; j < M; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << -1 << endl;
          return 0;
        }
        ans[s[i]] = c[i];
      }
    }
  }
  if (!o[0] && N != 1) {
    o[0] = true;
    ans[0] = 1;
  }
  for (int i = 0; i < N; i++) {
    if (!o[i])
      cout << 0;
    else
      cout << ans[i];
  }
  cout << endl;
}
