#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5, MOD = 1e9 + 7, MAXLG = log2(MAX) + 1;
const long long inf = 1e18 + 5;
int arr[MAX];
map<int, int> mp;
map<int, bool> vis;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1 && !b) ok = false;
    if (vis[a] && mp[a] != b) ok = false;
    vis[a] = true;
    mp[a] = b;
  }
  if (n == 1) {
    cout << mp[1] << "\n";
    return 0;
  }
  if (!ok) {
    cout << -1 << "\n";
    return 0;
  }
  string s = "";
  if (mp.find(1) != mp.end())
    s.push_back(mp[1] + '0');
  else
    s.push_back('1');
  for (int i = 2; i <= n; i++) {
    if (mp.find(i) == mp.end())
      s.push_back('0');
    else
      s.push_back(mp[i] + '0');
  }
  cout << s << "\n";
}
