import java.util.*;
public class Main {
private static final int LIM = 20;
public static void main
(String[] args
) { final Scanner sc
= new Scanner
(System.
in); while(sc.hasNext()) {
final int r = sc.nextInt();
final int n = sc.nextInt();
if(r == 0 && n == 0)
return;
final int[] xl = new int[n];
final int[] xr = new int[n];
final int[] h = new int[n];
for(int i = 0; i < n; i++) {
xl[i] = sc.nextInt();
xr[i] = sc.nextInt();
h[i] = sc.nextInt();
}
final int[] hmax = new int[2 * LIM];
for(int i = 0; i < n; i++)
for(int j = xl[i]; j < xr[i]; j++)
hmax
[j
+LIM
] = Math.
max(hmax
[j
+LIM
], h
[i
]); for(int i = -LIM; i < LIM; i++)
if(hmax
[i
+LIM
] == Integer.
MAX_VALUE) hmax[i+LIM] = 0;
double ans
= Double.
POSITIVE_INFINITY; for(int i = -r; i < r; i++) {
final int x = i < 0 ? ~i : i;
ans
= Math.
min(ans, hmax
[i
+LIM
] + r
- Math.
sqrt(r
* r
- x
* x
)); }
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwpwdWJsaWMgY2xhc3MgTWFpbiB7CiAgcHJpdmF0ZSBzdGF0aWMgZmluYWwgaW50IExJTSA9IDIwOwogIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgIGZpbmFsIFNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwogICAgd2hpbGUoc2MuaGFzTmV4dCgpKSB7CiAgICAgIGZpbmFsIGludCByID0gc2MubmV4dEludCgpOwogICAgICBmaW5hbCBpbnQgbiA9IHNjLm5leHRJbnQoKTsKICAgICAgaWYociA9PSAwICYmIG4gPT0gMCkKICAgICAgICByZXR1cm47CiAgICAgIGZpbmFsIGludFtdIHhsID0gbmV3IGludFtuXTsKICAgICAgZmluYWwgaW50W10geHIgPSBuZXcgaW50W25dOwogICAgICBmaW5hbCBpbnRbXSBoICA9IG5ldyBpbnRbbl07CiAgICAgIGZvcihpbnQgaSA9IDA7IGkgP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