#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, x, y, i, i1;
  cin >> n >> m;
  long long ans[n];
  for (i = 0; i < n; i++) ans[i] = -1;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    if (ans[x] == y || ans[x] == -1) {
      ans[x] = y;
    } else {
      cout << "-1\n";
      return 0;
    }
  }
  if (ans[0] == 0) {
    if (n == 1)
      cout << ans[i];
    else
      cout << "-1\n";
    return 0;
  }
  if (ans[0] == -1 && n == 1)
    ans[0] = 0;
  else if (ans[0] == -1)
    ans[0] = 1;
  for (i = 0; i < n; i++) {
    if (ans[i] == -1)
      cout << 0;
    else
      cout << ans[i];
  }
}
