#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
void setIO(string name = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if ((int)(name).size()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}
map<int, int> mpp;
int main() {
  setIO();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (mpp[x] != 0 && mpp[x] != y) {
      cout << -1;
      return 0;
    } else
      mpp[x] = y;
  }
  if (mpp[1] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++) cout << mpp[i];
}
