#include <bits/stdc++.h>
using namespace std;
int a[5];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, c, s;
  cin >> n >> m;
  memset(a, -1, sizeof a);
  if (n == 1 and m == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < m; ++i) {
    cin >> c >> s;
    if (a[c] == -1) {
      a[c] = s;
    } else if (a[c] != s) {
      cout << "-1";
      return 0;
    }
  }
  if (a[1] == 0) {
    cout << -1;
    return 0;
  }
  if (a[1] == -1) a[1] = 1;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  }
  return 0;
}
