#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const long long lim = (long long)3e16;
const int N = 1e5 + 5;
const int maxP = 7;
const int mod = 1e9 + 7;
const long long oo = 1e18 + 5;
int n, m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  string ans;
  vector<int> minn(n + 1, 10);
  for (int i = 0; i < m; ++i) {
    int pos, num;
    cin >> pos >> num;
    if (pos == 1 && num == 0) continue;
    minn[pos] = min(minn[pos], num);
  }
  if (minn[1] == 10) return cout << -1, 0;
  for (int i = 1; i <= n; ++i) {
    if (minn[i] == 10 && i != 1) minn[i] = 0;
    ans += (char)(minn[i] + '0');
  }
  cout << ans;
}
