#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int ans[10];
map<int, int> vis;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (a == 1 && b == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (vis[a] && ans[a] != b) {
      cout << "-1" << endl;
      return 0;
    }
    vis[a] = 1;
    ans[a] = b;
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1 && !ans[i])
      cout << "1";
    else
      cout << ans[i];
  }
  cout << endl;
  return 0;
}
