#include <bits/stdc++.h>
using namespace std;
int a[5];
void solve() {
  int n, m;
  cin >> n >> m;
  memset(a, -1, sizeof a);
  int sum = 0;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (a[s] == -1 || a[s] == c) {
      sum += c;
      a[s] = c;
    } else {
      cout << -1 << endl;
      return;
    }
  }
  if (n > 1 && sum == 0) {
    cout << -1 << endl;
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
